1.

Solve : Parse file names and rearrange variables for new name?

Answer»

I'm trying to RENAME a group of files that are named like this "KSFO-AM 05 to 10 (KSFO) 11_13_12 02.mp3" where I want to parse the name by the spaces found in the name and then re-arrange the name. I'm trying to use the FOLLOWING command:

for /f "tokens=1-7 usebackq delims=" "" %%A in ('dir /b ""KFSO-AM *02.mp3""') do Rename ""%%A %%B %%C %%D %%E %%F %%G"" "%%A%%C%%D%%G"

I'm not sure what I'm doing wrong... Must have something to do with spaces because I've used this parsing by other characters...

Thanks for any help!1. If you specify backq in the options block you should use backquotes to surround the command in the dataset. You used single QUOTES which are not the same.

2. Not sure what is going on in the options block. Looks weird at the end with all those quotes. See below. (You don't QUOTE a space in the options block; you just do delims= ")

3. You got the S and F opposite ways around in the dir /b wildcard and in the file name format. You showed the file format as KSFO-AM bla bla bla whereas dir /b is looking for filespec KFSO-AM bla bla bla

4. You seem to be too fond of quotes!

Having fixed these things and made the loop multiline I came up with this

(I have one file called KSFO-AM 05 to 10 (KSFO) 09_13_12 02.mp3 in the folder)

@echo off
for /f "tokens=1-7 usebackq delims= " %%A in (`dir /b "KSFO-AM *02.mp3"`) do (
echo Tokens:
echo A %%A
echo B %%B
echo C %%C
echo D %%D
echo E %%E
echo F %%F
echo G %%G
echo Command:
echo Rename "%%A %%B %%C %%D %%E %%F %%G" "%%A%%C%%D%%G"
)


Result:

Tokens:
A KSFO-AM
B 05
C to
D 10
E (KSFO)
F 09_13_12
G 02.mp3
Command:
Rename "KSFO-AM 05 to 10 (KSFO) 09_13_12 02.mp3" "KSFO-AMto1002.mp3"
I believe the quotes were trying to account for problems I was having with the wrong file name and going way down the wrong road! Thanks a lot for your help!



Discussion

No Comment Found