批处理文件删除选定的文件
在大多数现代系统中,系统会自动创建不必要的额外文件。如何创建一个 .bat 文件,利用清单来删除不在其中的任何文件?
这对于删除我创建的自定义文件中自动生成的备份文件、绘图日志、错误日志等非常有用。
In most modern systems, the system will automatically create extra files that are unnecessary. How can I create a .bat file that makes use of a checklist to delete any file that isn't on it?
This would be useful for removing automatically generated backup files, plot logs, error logs, etc. in the customization files I have created.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个,确保将 SEARCHDIR 设置为真实目录,并使用要保留的文件填充 keep.txt,每行 1 个文件,使用包括目录的完整路径。如果您不想使用该目录,请调整
DIR /S /B
命令,使其输出的格式与 keep.txt 中的格式相同Try this, make sure to set SEARCHDIR to the real dir, and populate keep.txt with the files you want to keep, 1 file per line, use the full path including the dir. If you don't want to use the dir, adjust the
DIR /S /B
command so it outputs the same format as what is in your keep.txt创建一个名为“deletestuff.bat”的文件(或者任何您想要的名称,只要它是
.bat
)。接下来,填写:其中
.tmp
和.blah
是您要删除的文件的扩展名(它们可能是.log,例如)。首先通过将文件示例复制到新文件夹并在那里运行新的
.bat
进行测试,以确保它不会删除重要的内容。Make a file called 'deletestuff.bat' (or whatever you want it to be called, as long as it is a
.bat
). Next, fill it with:Where
.tmp
, and.blah
are the extensions of the files that you would like to delete (they might be.log
, for instance). Test it first by copying a sample of files into a new folder and running the new.bat
there, just to make sure it doesn't delete important things.