从列表读取后,DOS批量创建带有子文件夹的文件
我有一个 txt 文件,其中包含带有目录结构的文件名列表。下面的示例(中间没有空行):
C:\createdocs\1.txt
C:\createdocs\2.txt
C:\createdocs\mydocs\3.txt
C:\createdocs\mysubdocs\4.txt
C:\createdocs\5.txt
我想创建一个批处理文件,该文件将从该文件中逐一读取,并在路径处创建具有一些虚拟值的文件(“这是一个测试文件”)每行提供。如果该目录不存在,也创建该目录。是否可以使用批处理脚本?
I have a txt file which has a list of filenames with directory structure. Example below (w/o the blank lines in between):
C:\createdocs\1.txt
C:\createdocs\2.txt
C:\createdocs\mydocs\3.txt
C:\createdocs\mysubdocs\4.txt
C:\createdocs\5.txt
I want to create a batch file which will read from this file one by one and will create the file with some dummy value ("this is a test file") at the path provided at each line. If the directory doesn't exist, create the directory as well. Is it possible using the batch scripts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 cmd shell 中,您可以使用
for /f %var in (file.txt)
按顺序处理文件的每一行。然后使用此答案中详细介绍的内容处理您检索到的每一行以提取路径。然后,只需执行mkdir
,然后执行echo 'this is a dummy file' > 就可以了。文件
In a cmd shell, you can use
for /f %var in (file.txt)
to process each line of the file sequentially. Then use the stuff detailed in this answer to process each line you've retrieved to extract the path. Then it's a simple matter of doing amkdir
followed byecho 'this is a dummy file' > thefile