Page 1 of 1

how to delete files of within folders with same name as files based upon a list of files

Posted: 31 Oct 2017 07:57
by goodywp
I had two tasks as below:

.../app/ (under this folder, there are hundreds of files, some are matching the files listed in applist.txt)
.../comp/ (under this folder there are hundreds of subfolders, their names are exactly same as file names under this subfolders, some subfolders are matching the names as listed in applist.txt)

1) delete all files listed in applist.txt within app folder

I have the following code to delete:

Code: Select all

for /f %%i in (applist.txt) do del %%i


2) under folder of comp, there are some subfolders which names are exactly same as files listed in applist.txt, under this subfolder, there is only one file in it with the same name. Now I try to delete this file under this subfolder based upon the above list applist.txt and keep the subfolder

here is the applist.txt

    1240047901010300_cfgCustom.P3P
    1240000272010200_CoreProxy.P3A
    8295431004_Dialog.P3L
    8295522003_E2EE.P3A
    8295411001_GMHCA.P3A
    8295000512_KIA.P3A
    8295441001_XmlPrint.P3L
    8295421001_TlvSqlite.P3L
    8520681003_TD_Host.P3L
    8520671004_TD_Cust.P3L
    8295291004_CoreApp.P3A
    8296121001_Database.P3L
    8295010512_TSA.P3A
    8295861003_TSI.P3A
    8295150100_DLG.P3P
    8295160100_RCPTS.P3P
    8295170100_REPTS.P3P
    8296200100_TD.P3P
    8520290100_TDTMS.P3P
    8520190100_TDING.P3P
    8296520100_COREGL.P3P
    8520730100_GL_RSC.P3P
    8520700100_TDCFG.P3P

Thanks

Re: how to delete files of within folders with same name as files based upon a list of files

Posted: 31 Oct 2017 08:06
by aGerman
goodywp wrote: 2) under folder of comp, there are some subfolders which names are exactly same as files listed in applist.txt

Does "exactly same" mean that the subfolder's name is e.g. "1240047901010300_cfgCustom.P3P" or is it rather "1240047901010300_cfgCustom"?

Steffen

Re: how to delete files of within folders with same name as files based upon a list of files

Posted: 31 Oct 2017 08:12
by goodywp
1240047901010300_cfgCustom.P3P instead of 1240047901010300_cfgCustom

Thanks

Re: how to delete files of within folders with same name as files based upon a list of files

Posted: 31 Oct 2017 08:19
by aGerman
If the list and the script are in the parent folder of app and comp this should work.

Code: Select all

@echo off & setlocal
for /f "tokens=*" %%i in ('type "applist.txt"') do (
  del "app\%%i"
  del "comp\%%i\%%i"
)

Steffen

Re: how to delete files of within folders with same name as files based upon a list of files

Posted: 31 Oct 2017 12:40
by goodywp
Thank you Steffen!!