File process under each subfolder of a certain path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
autonicknan
Posts: 19
Joined: 01 Mar 2013 11:44

File process under each subfolder of a certain path

#1 Post by autonicknan » 25 Jun 2014 06:58

Hello,

I want to create a bat file with which a specific action will be performed under all the subfolders of a certain path.

I have already made a file with which I can execute my action under a specific folder(C:\IPSL\T125\LM55786_UUS\SIPSTK\PARSING_MIDDLE\PARSING_MIDDLE10\main) individually:

echo off

cd C:\IPSL\T125\LM55786_UUS\SIPSTK\PARSING_MIDDLE\PARSING_MIDDLE10\main

del *.ITS
del *.TRC
del *.dbc

ipslc /B /p%toolpath%\ipsl\sip01\sip01.prf -cits -m "*.ctl"
ipslc /B /p%toolpath%\ipsl\sip01\sip01.prf -cits -m "*.scr"

echo
pause


The script above works fine but just for the files under the specific folder "PARSING_MIDDLE10\main".

What I need is this actions to be performed to all subfolders under "C:\IPSL\T125\LM55786_UUS\SIPSTK\PARSING_MIDDLE\".

I have modified the bat file as below but it does not work :(

echo off

cd C:\IPSL\T125\LM55786_UUS\SIPSTK\PARSING_MIDDLE\

for /r %%g in (.) do

del *.ITS
del *.TRC
del *.dbc

ipslc /B /p%toolpath%\ipsl\sip01\sip01.prf -cits -m "*.ctl"
ipslc /B /p%toolpath%\ipsl\sip01\sip01.prf -cits -m "*.scr"

echo
pause



Any idea;

Thanks
Nikos

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: File process under each subfolder of a certain path

#2 Post by foxidrive » 25 Jun 2014 07:26

Try this but backup your files first.

Code: Select all

echo off

for /d /r "C:\IPSL\T125\LM55786_UUS\SIPSTK\PARSING_MIDDLE" %%g in (*) do (
pushd "%%g"
echo "%%g"
del *.ITS
del *.TRC
del *.dbc

ipslc /B /p%toolpath%\ipsl\sip01\sip01.prf -cits -m "*.ctl"
ipslc /B /p%toolpath%\ipsl\sip01\sip01.prf -cits -m "*.scr"
popd
)
echo done
pause

autonicknan
Posts: 19
Joined: 01 Mar 2013 11:44

Re: File process under each subfolder of a certain path

#3 Post by autonicknan » 25 Jun 2014 10:23

Hello foxidrive,

This works...:)

Thank you very much!!!

Nikos

Post Reply