batch del files in subfolders only certain file exist

goodywp

New member
Local time
2:19 AM
Messages
3
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 Computer My Computer

Computer type
PC/Desktop
OS
Ontario
Welcome to the forum. if I understand you you want

Code:
cd\test
del *.p3* /s
 
Last edited by a moderator:

My Computer My Computer

Computer type
PC/Desktop
OS
win 8 32 bit
Batch for Delete all Occurences in SubFolders

I think you need the following :D:

Code:
ECHO OFF
CLS

del /s "c:\directory\*.pkg"

@ pause

Best regards
 
Last edited by a moderator:

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
unknow
OS
Windows 8 32 bit
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 Computer My Computer

Computer type
PC/Desktop
OS
Ontario
Post two should do that
 

My Computer My Computer

Computer type
PC/Desktop
OS
win 8 32 bit
Try this

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
 
Last edited by a moderator:

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
unknow
OS
Windows 8 32 bit
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 Computer My Computer

Computer type
PC/Desktop
OS
Ontario
It should delete any file that has .P3 and anything else the /s tells it to do the same in sub directory
 

My Computer My Computer

Computer type
PC/Desktop
OS
win 8 32 bit
Back
Top