for /f has a problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wmaddox3
Posts: 1
Joined: 26 Oct 2011 15:29

for /f has a problem

#1 Post by wmaddox3 » 26 Oct 2011 15:54

i've been lurking here a couple years, great site - thanks to all...

found a problem with FOR finding a shortpath name. when any foldername has consecutive spaces... I'm just careful about my foldernames now...

for /f "delims=" %%a IN ("%filename%") DO echo %%~fsa & set filename=%%~fsa

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: for /f has a problem

#2 Post by abc0502 » 26 Oct 2011 23:15

I Guess the code should be like that:

Code: Select all

FOR /F "tokens= delims=" %%a in ('find /i "X" "path\file"') do echo %%a & set p=%%a

> change the tokens and the delims according to the file
> "X" is the word in the beginning of the line and before the "delims"
> "path\file" is the path of the file
> "p" is the variable u set for the output result u find in the file
Example: find fire fox profile name, display it and set it to "p" [in windows XP]

Code: Select all

FOR /F "tokens=2 delims==" %%a in ('find /i "path=" "%appdata%\mozilla\firefox\profiles.ini"') do echo %%a & set p=%%a


i hope that help u. :)

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

Re: for /f has a problem

#3 Post by aGerman » 28 Oct 2011 11:14

@ wmaddox3
Sorry, but I can't comprehend the problem. Of course it will fail if the file doesn't exist...

Regards
aGerman

Post Reply