Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

# Windows 7: batch del files in subfolders only certain file exist

 05 Sep 2017 #1 goodywp Ontario 3 posts batch del files in subfolders only certain file exist Hi all, I just want a batch file to delete all files with extension *.P3? in all subfolders on condition only some file exist in these subfolders like *.pkg file C:\test\abc\*.P3A, *.pkg C:\test\def\*.P3L C:\test\ghi\*.P3P, *.pkg So the script should only delete *.P3A in abc folder and also *.P3P in ghi folder Thanks My System Specs
 .
 05 Sep 2017 #2 samuria win 8 32 bit 1,564 posts crewe uk Welcome to the forum. if I understand you you want Code: cd\test del *.p3* /s My System Specs
 05 Sep 2017 #3 SmithJohn Windows 8 32 bit 2 posts Batch for Delete all Occurences in SubFolders I think you need the following : Code: ECHO OFF CLS del /s "c:\directory\*.pkg" @ pause Best regards My System Specs
 .
 06 Sep 2017 #4 goodywp Ontario 3 posts how to delete certain files only some file exist in subfolder in batch Thanks to both of your replies. What I really want is a batch file to do: 1) if the *.pkg file exist in subfolder 2) then delete *.P3? files, it could be *.P3A, *.P3P, or *.P3L C:\test\abc\*.P3A, *.pkg C:\test\def\*.P3L C:\test\ghi\*.P3P, *.pkg So the batch script should only delete *.P3A in abc folder and also *.P3P in ghi folder Thanks My System Specs
 06 Sep 2017 #5 samuria win 8 32 bit 1,564 posts crewe uk Post two should do that My System Specs
 06 Sep 2017 #6 SmithJohn Windows 8 32 bit 2 posts Try this    Quote: Originally Posted by goodywp Thanks to both of your replies. What I really want is a batch file to do: 1) if the *.pkg file exist in subfolder 2) then delete *.P3? files, it could be *.P3A, *.P3P, or *.P3L C:\test\abc\*.P3A, *.pkg C:\test\def\*.P3L C:\test\ghi\*.P3P, *.pkg So the batch script should only delete *.P3A in abc folder and also *.P3P in ghi folder Thanks I'm sorry, I was on the moon Ok, you can adapt the following code to what you need, I hope it's what you're looking for. Code: ECHO OFF CLS if exist c:\directory1\*.pkg goto deleting1 if exist c:\directory2\*.pkg goto deleting2 :deleting1 del "c:\directory1\*.pkg" del "c:\directory1\*.P3A" del "c:\directory1\*.P3L" del "c:\directory1\*.P3P" :deleting2 del "c:\directory2\*.P3A" del "c:\directory2\*.P3L" del "c:\directory2\*.P3P" @ pause My System Specs
 06 Sep 2017 #7 goodywp Ontario 3 posts Hi Samuria, there is also the below folder which has *.P3L file and could be deleted as well. The intended is not deleting the file in the folder since it doe not have*.pkg file in this folder C:\test\def\*.P3L Thanks My System Specs
 06 Sep 2017 #8 samuria win 8 32 bit 1,564 posts crewe uk It should delete any file that has .P3 and anything else the /s tells it to do the same in sub directory My System Specs