[英]Delete Files in Folder B that have the same Prefix as files in Folder A Batch File
I want to do the following. 我要执行以下操作。 If I have folder A:
如果我有文件夹A:
File1.ext
File2.ext
File3.ext
I want to delete anything in folder B that begins with the same prefix. 我想删除文件夹B中以相同前缀开头的所有内容。 So if I have this in folder B:
因此,如果我在文件夹B中有此文件夹:
File1-1.ext
File2-3.ext
I want them to be deleted. 我希望将其删除。
I've been trying to use this: 我一直在尝试使用此:
For %%F In ("C:\FolderA\*.*") Do If Exist "C:\FolderB\%%~nF" Del "C:\FolderB\%%~nF"
But it won't work for me if there is a "-1" for instance on the file in folder B. I tried using an asterisk but that did not work. 但是,如果文件夹B中的文件上有一个“ -1”字样,它对我将不起作用。我尝试使用星号,但这没有用。 I'm totally brand new to this, and your help is appreciated.
我对此是全新的,感谢您的帮助。 Thanks!
谢谢!
What you have to do is to take the filename ONLY from files in FolderA
and search if exist in FolderB
. 你所要做的是采取只在备份文件的
FolderA
,如果存在于搜索FolderB
。 So, you need to try something like this: 因此,您需要尝试这样的事情:
for %%I IN ("C:\FolderA\*.*") do del /q "C:\FolderB\%%~nI*"
where %%~nI
means filename only of files found in FolderA
. 其中
%%~nI
表示仅在FolderA
找到的文件的文件名。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.