I just want a batch file to delete all files with extension *.P3? in all subfolders on condition of only some file exist in these subfolders like *.pkg file
for example:
C:\test\abc\*.P3A
C:\test\abc\*.pkg
C:\test\def\*.P3L
C:\test\ghi\*.P3P
C:\test\ghi\*.pkg
So the batch run results should be as below: both the *.P3A file in abc folder and *.P3P file in ghi folder should be deleted. But the *.P3L file should not be deleted since it does not have *.pkg file in folder of def.
Thanks
Batch delete certain files only certain file exist in subfolder
Moderator: DosItHelp
Batch delete certain files only certain file exist in subfolder
Last edited by goodywp on 06 Sep 2017 12:11, edited 1 time in total.
Re: Batch delete certain files only certain file exist in subfolder
You are going to need to be more specific then that. Please provide a true real world example with actual file names.
Re: Batch delete certain files only certain file exist in subfolder
So what I understood is that C:\test is the root folder. The .P3L files you missed to mention above would be deleted,
too.
Steffen
too.
Code: Select all
del /f /s /q "C:\test\*.p3?"
Steffen
Re: Batch delete certain files only certain file exist in subfolder
Hi Squashman,
Here is the example:
..\Customer Download\TETRA\TELIUM3\TSA
8295010512_TSA.M70
8295010512_TSA.P3P
8295010512_TSA.P3P.jsat
8295010512_TSA.P3P.pkg
Contents.lst
Schemes to Sign_for_829501.doc
..\Customer Download\TETRA\TELIUM3\KIA
8295000512_KIA.M70
8295000512_KIA.P3A
8295000512_KIA.P3A.jsat
8295000512_KIA.P3A.pkg
Contents.lst
Schemes to Sign_for_829500.doc
..\Customer Download\TETRA\TELIUM3\E2EE
8295522003_E2EE.M70
8295522003_E2EE.P3A
8295522003_E2EE.P3A.jsat
8295522003_E2EE.P3A.pkg
Contents.lst
Schemes to Sign_for_829552.doc
..\Customer Download\TETRA\ALL_TERMINALS_DLLSQLITE
9990044299020301_DLLSQLITE.P3L
9992048007111202_OPT_SQLI.P3P
ALL_TERMINALS_DLLSQLITE.M70
Contents.lst
Th batch run should delete all *.P3? (not *.P3A.jsat nor *.P3A.pkg) files in above except this folder "ALL_TERMINALS_DLLSQLITE" since this folder does not meet the condition which does not have *.pkg file in it. So after run the above should looks like this:
..\Customer Download\TETRA\TELIUM3\TSA
8295010512_TSA.M70
8295010512_TSA.P3P.jsat
8295010512_TSA.P3P.pkg
Contents.lst
Schemes to Sign_for_829501.doc
..\Customer Download\TETRA\TELIUM3\KIA
8295000512_KIA.M70
8295000512_KIA.P3A.jsat
8295000512_KIA.P3A.pkg
Contents.lst
Schemes to Sign_for_829500.doc
..\Customer Download\TETRA\TELIUM3\E2EE
8295522003_E2EE.M70
8295522003_E2EE.P3A.jsat
8295522003_E2EE.P3A.pkg
Contents.lst
Schemes to Sign_for_829552.doc
..\Customer Download\TETRA\ALL_TERMINALS_DLLSQLITE
9990044299020301_DLLSQLITE.P3L
9992048007111202_OPT_SQLI.P3P
ALL_TERMINALS_DLLSQLITE.M70
Contents.lst
I hope that I put the requirement clear
Thanks
Here is the example:
..\Customer Download\TETRA\TELIUM3\TSA
8295010512_TSA.M70
8295010512_TSA.P3P
8295010512_TSA.P3P.jsat
8295010512_TSA.P3P.pkg
Contents.lst
Schemes to Sign_for_829501.doc
..\Customer Download\TETRA\TELIUM3\KIA
8295000512_KIA.M70
8295000512_KIA.P3A
8295000512_KIA.P3A.jsat
8295000512_KIA.P3A.pkg
Contents.lst
Schemes to Sign_for_829500.doc
..\Customer Download\TETRA\TELIUM3\E2EE
8295522003_E2EE.M70
8295522003_E2EE.P3A
8295522003_E2EE.P3A.jsat
8295522003_E2EE.P3A.pkg
Contents.lst
Schemes to Sign_for_829552.doc
..\Customer Download\TETRA\ALL_TERMINALS_DLLSQLITE
9990044299020301_DLLSQLITE.P3L
9992048007111202_OPT_SQLI.P3P
ALL_TERMINALS_DLLSQLITE.M70
Contents.lst
Th batch run should delete all *.P3? (not *.P3A.jsat nor *.P3A.pkg) files in above except this folder "ALL_TERMINALS_DLLSQLITE" since this folder does not meet the condition which does not have *.pkg file in it. So after run the above should looks like this:
..\Customer Download\TETRA\TELIUM3\TSA
8295010512_TSA.M70
8295010512_TSA.P3P.jsat
8295010512_TSA.P3P.pkg
Contents.lst
Schemes to Sign_for_829501.doc
..\Customer Download\TETRA\TELIUM3\KIA
8295000512_KIA.M70
8295000512_KIA.P3A.jsat
8295000512_KIA.P3A.pkg
Contents.lst
Schemes to Sign_for_829500.doc
..\Customer Download\TETRA\TELIUM3\E2EE
8295522003_E2EE.M70
8295522003_E2EE.P3A.jsat
8295522003_E2EE.P3A.pkg
Contents.lst
Schemes to Sign_for_829552.doc
..\Customer Download\TETRA\ALL_TERMINALS_DLLSQLITE
9990044299020301_DLLSQLITE.P3L
9992048007111202_OPT_SQLI.P3P
ALL_TERMINALS_DLLSQLITE.M70
Contents.lst
I hope that I put the requirement clear
Thanks
Re: Batch delete certain files only certain file exist in subfolder
The line I posted above should work. Just customize the path (and backup the files before you try).
Also move folder ALL_TERMINALS_DLLSQLITE to another location (on the same drive) in order to exclude it. Don't worry, moving files on the same volume will not cause physical moving.
Steffen
Also move folder ALL_TERMINALS_DLLSQLITE to another location (on the same drive) in order to exclude it. Don't worry, moving files on the same volume will not cause physical moving.
Steffen
Re: Batch delete certain files only certain file exist in subfolder
Seems like in its simplest form you want to delete a corresponding file to the PKG file.
Code: Select all
FOR /R %%G IN (*.PKG) DO IF EXIST "%%~dpnG" DEL "%%~dpnG"
Re: Batch delete certain files only certain file exist in subfolder
Hi Squashman,
It is indeed the simplest form I can look for so far! and best of all it works as expected!!
A big thanks to both of you and Steffen for quick replies....
I am blessed by this forum that I had genuine help...
Cheers!
It is indeed the simplest form I can look for so far! and best of all it works as expected!!
A big thanks to both of you and Steffen for quick replies....
I am blessed by this forum that I had genuine help...
Cheers!