如何在Windows中批量创建一系列文件夹(000-999)?


15

我需要在目录中创建1000个文件夹,编号为000到999。我该如何使用cmd(即Windows命令行)?


像这样的问题我通常会指向python的人。Windows的命令行远非强大,IMO需要一些东西来补充它。
Phoshi 2010年

1
我只需要做一次,不要只是为了安装python ...
user11955 2010年

1
不,你会保留Python的其他东西;)
Ignacio Vazquez-Abrams 2010年

Answers:


25
for /l %i in (0,1,9) do md 00%i
for /l %i in (10,1,99) do md 0%i
for /l %i in (100,1,999) do md %i

文档中的说明(即for /?在命令提示符下键入):

Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

  %variable  Specifies a single letter replaceable parameter.
  (set)      Specifies a set of one or more files.  Wildcards may be used.
  command    Specifies the command to carry out for each file.
  command-parameters
             Specifies parameters or switches for the specified command.

...

FOR /L %variable IN (start,step,end) DO command [command-parameters]

    The set is a sequence of numbers from start to end, by step amount.
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
    generate the sequence (5 4 3 2 1)

1
这是某种外国语言吗?无论如何,它都很棒!谢谢!
user11955 2010年

真棒!我刚尝试过。您是否介意解释语法或给出解释的链接?
Christopher Bottoms 2015年

1
@ChristopherBottoms:我希望你已经找到了语法。但是如果您仍然需要它,请转到cmd窗口并输入/?
Codism 2015年

非凡的答案!
Brainmaniac

-1
@ECHO OFF && CLS

SET /P x=Insert the name of the place: 
SET /P y=Insert de number of the records: 

SET /A start=1
SET /A z=y+1

REM start the loop
:MKDIR

REM make the directory
MKDIR %x%"__"%start%

REM increment by 1
SET /A start=start+1

REM if we're at the end, return
IF %start%==%z% (GOTO :EOF) ELSE (GOTO :MKDIR)

它作为一个.bat文件
NeoMati

它不起作用。OP想要带有0前缀(000-999)的名字,并且他只想要没有任何前缀的数字。您的代码生成的数字不带0前缀,您还添加了奇怪的前缀。例如,如果这个地方的名字是abc你创建的abc"__"0abc"__"1... abc"__"10...abc"__"999
phuclv
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.