windows 从 Cmd 行上的文件中批量删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1178942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Batch Delete Files From File On Cmd Line
提问by Ken White
I have a long list of file names in a txt file, which I generated using
我在 txt 文件中有很长的文件名列表,这是我使用生成的
findstr /M "string here" *.* > c:\files.log
The file is about 3mb. Now i want to delete all of those files. I tried del < c:\files.log but that doesn't work. What should I use?
文件大约3mb。现在我想删除所有这些文件。我试过 del < c:\files.log 但这不起作用。我应该使用什么?
回答by CMB
Batch for NT on up supports a FOR loop with special switches
Batch for NT on up 支持带有特殊开关的 FOR 循环
FOR /Fseems to fit what you want as it allows input from a file and positional delimiters.
FOR /F似乎符合您的要求,因为它允许从文件和位置分隔符输入。
See .. http://ss64.com/nt/for_f.html
见.. http://ss64.com/nt/for_f.html
You are looking for something like...
您正在寻找类似...
for /F "tokens=*" %%a in (files.log) DO DELETE "%%a"
for /F "tokens=*" %%a in (files.log) DO DELETE "%%a"
回答by Ken White
This should work:
这应该有效:
for /f "tokens=1*" %a in (filelist.txt) do del %a
回答by Avdi
If you install Cygwin or something similar it's just:
如果你安装 Cygwin 或类似的东西,它只是:
cat files.log | xargs rm
回答by Fernatit
You must have %%a and not %a inside the batch file %a for cmd
对于 cmd,批处理文件 %a 中必须有 %%a 而不是 %a