使用批处理脚本创建X个目录

问题描述:

我目前正在尝试编写一个快速批处理脚本,它将循环1到X并创建一个空的.txt文件的目录。使用批处理脚本创建X个目录

这是我到目前为止写:

set x = 10 

:DoUntil 

MkDir "Test Location %x%" 
echo. 2>"Test Location %x%\EmptyFile.txt" 
set x -= 1 

IF x > 0 goto DoUntil 

%X%的不写出1,2,3 ......在每个循环,并没有被因为文件夹中创建的文件不存在。

任何人都可以提供帮助,以便我可以修复此脚本以创建以下目录和文件?

Test Folder 1\EmptyFile.txt 
Test Folder 2\EmptyFile.txt 
Test Folder 3\EmptyFile.txt 
Test Folder 4\EmptyFile.txt 
Test Folder 5\EmptyFile.txt 
Test Folder 6\EmptyFile.txt 
Test Folder 7\EmptyFile.txt 
Test Folder 8\EmptyFile.txt 
Test Folder 9\EmptyFile.txt 
Test Folder 10\EmptyFile.txt 

我打开PowerShell实施或更好的东西,如果你有一个建议。这是为了帮助质量保证人员测试文件拾取服务,该服务将在整个网络中从特定目录中抽出并收集文件。

在PowerShell中

 
foreach($i in 1..100) 
{ 
    md "Test Folder $i" -force | out-null #or New-Item
Set-Content -Path (join-path "Test Folder $i" "EmptyFile.txt") -Value $null
}

感谢:While loop in batch

setlocal enableextensions enabledelayedexpansion 
set /a "x = 0" 
:while1 
    if %x% leq 10 (
     echo %x% 
     MkDir "Test Location %x%" 
     echo. 2>"Test Location %x%\EmptyFile.txt" 
     set /a "x = x + 1" 
     goto :while1 
    ) 
endlocal 
+0

感谢完美地工作,如果我能接受2个答案我会接受你和@ mikeblake的 – Mark 2011-03-30 15:50:03