Windows:比较文件夹中的文件并删除不存在的文件 [英] Windows: compare files in folders and delete non existent
问题描述
我在Windows上有巨大的目录+包含文件的子目录. 在Windows命令行上(或通过脚本),我想比较两个文件夹并从子文件夹中删除不在主文件夹中的文件.
I have huge directories + subdirs containing files on Windows. On the windows command line (or through a script) I'd like to compare two folders and delete files from the subfolder that are not in the main folder.
在下面的示例中,应从子文件夹中删除偶数个文件.
In the example below the even numbered files should be deleted from the subfolder.
folder: C:\folder1
file1.jpg
file3.jpg
file4.jpg
file7.jpg
file9.jpg
subfolder: C:\folder1\RAW\
file1.CR2
file2.CR2
file3.CR2
file4.CR2
file5.CR2
file6.CR2
file7.CR2
file8.CR2
file9.CR2
我尝试了在这里找到的几个脚本,但是没有一个可以完成任务.感谢您的帮助!
I have tried several scripts I found here, but non of them do the job. Any help is appreciated!
推荐答案
感谢大家的投入,感谢您的投入,我想出了一个解决方案.在命令行(当然是Windows)上使用它时,效果很好.
Thanks for the input everyone, I came up with a solution also thanks to your input. It works perfect when using it on the command line (Windows of course).
删除之前查看列表:
for %F in ("C:\folder1\RAW\*.CR2") do @if not exist "C:\folder1\%~nF.jpg" echo del "%F"
要删除,请删除"echo"
To delete, remove 'echo'
for %F in ("C:\folder1\RAW\*.CR2") do @if not exist "C:\folder1\%~nF.jpg" del "%F"
希望这对一些人也有用!
Hope this will be of use for some out there as well!
这篇关于Windows:比较文件夹中的文件并删除不存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!