简体   繁体   English

删除文件夹B中与文件夹A批处理文件中的文件具有相同前缀的文件

[英]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.

相关问题 批处理文件删除文件和文件夹 - Batch file to delete files and folder 批处理-删除文件夹和所有文件 - Batch - Delete folder and all files 如何使用Windows Batch Scripting从文件夹“A”中删除文件夹“A”中的所有文件/文件夹? - How to delete all files/folders from a folder 'A' which are not present in the folder 'B', using Windows Batch Scripting? 使用批处理删除文件夹中除列表中的文件以外的所有文件 - Delete all files in folder except file in list using batch Windows批处理命令用于从一个文件夹中删除文件 - Windows batch command to delete files from a folder except one file 批处理文件在文件夹中经过一定时间后删除文件? - Batch file to delete files after a certain amount of time in folder? 从当前文件夹中的所有文件以及子文件夹Windows批处理中的文件中删除前缀 - Remove Prefix from all file in current folder as well as files in subfolder windows batch 使用Windows批处理文件将多个文件从具有相同文件名的不同文件夹复制到一个公用文件夹 - Copy multiple files from different folder with same filename to one common folder using windows batch file 批处理文件/ Powershell-枚举文件夹中的文件 - Batch File/Powershell - enumerating files in a folder 将文件移动到指定文件夹的批处理文件 - Batch file for moving files to specified folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM