Articles

Solved Nesting For loops In Batch Scripting

November 21, 2012 at 16:47:54
Specs: Windows 7 Home Premium x64, DualCore 2.10GHz/4GB

Not sure if this is possible in batch but will ask.

I have a folder where the batch file will run from that contains numbered folders i.e. 00001, 00002,...99999. Each one of these folders refers to a member/client.

These 'client' folders may contain files/folders depending on my monthly output. 99% of the time they will go at least one folder deep, occasionally they may go 2 folders deep.

For example

Folder '00001'
Folder 'New Year 2012'
Folder 'Pre-midnight Build up'
Track 01.mp3
Track 02.mp3
Folder 'Midnight to end'
Track 01.mp3
Track 02.mp3
Folder '00005'
Folder 'New Year 2012'
Folder 'Pre-midnight Build up'
Track 01.mp3
Track 02.mp3
Folder 'Midnight to end'
Track 01.mp3
Track 02.mp3

I already have a way of embedding dates & times into the mp3's for my own records, I would now like to also embed the customer ID along with the date & time.

I have a text file clients.txt that contains all the clients ID's if that may be easier to use.

Not every client will have each release so not every folder will contain mp3's so its only if the folder/sub folders contain mp3's so I essentially need something along the lines of..

For this folder scan sub folder & sub folders for mp3's then do whatever to mp3.

I already have this for the final iterations of embedding the mp3's courtesy of nbrane

for %%a in (*.mp3) do echo %date% %time%>>%%a

now I'd like to expand it as stated above somehow.

Thanks


See More: Nesting For loops In Batch Scripting

Report •


#1
November 21, 2012 at 20:09:25
✔ Best Answer

@echo off & setlocal
:: main is where-ever you have all your clients planted (00001, 00005,etc)
cd main
for /d %%a in (*) do (
pushd %%a
for /r %%b in (*.mp3) do (
>>%%b echo %date% %time% %%a
)
popd
)
::===== end script

Report •

#2
November 22, 2012 at 03:39:25

Again nbrane comes to my rescue thank you so, so much. Am going away to find out about pushd & popd now, the rest I understand in as much as I can at the moment.

I am definitely going to learn more about batch scripts, never realized how useful it could be.

Again thank you nbrane.


Report •

Related Solutions


Ask Question