使用批处理脚本创建 X 个目录
我目前正在尝试编写一个快速批处理脚本,它将循环 1 到 X 并创建一个包含空 .txt 文件的目录。
这是我到目前为止所写的:
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 实现或更好的东西。它是为了帮助 QA 人员测试文件拾取服务,该服务将出去并从网络上的特定目录收集文件。
I am currently trying to write a quick batch script which will loop 1 through X and create a directory with an empty .txt file.
Here is what I have written so far:
set x = 10
:DoUntil
MkDir "Test Location %x%"
echo. 2>"Test Location %x%\EmptyFile.txt"
set x -= 1
IF x > 0 goto DoUntil
%x% isn't writing out 1,2,3... in each loop and the file isn't being created because the folder doesn't exist.
Can anyone help so that I can fix this script to have the following directories and files created?
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
I am open for a PowerShell implementation or something better if you have a suggestion. It's to help a QA person test a File Pickup service which will go out and collect files from specific directories all over the network.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢:批量循环
Thanks to: While loop in batch
在 Powershell 中
In Powershell