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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

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

#1 Post by goodywp » 31 Oct 2017 07:57

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
Last edited by goodywp on 31 Oct 2017 08:10, edited 1 time in total.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 31 Oct 2017 08:06

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

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

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

#3 Post by goodywp » 31 Oct 2017 08:12

1240047901010300_cfgCustom.P3P instead of 1240047901010300_cfgCustom

Thanks

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#4 Post by aGerman » 31 Oct 2017 08:19

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


Post Reply