Hi
I have a file temp.txt with the following string content
C:\folder\file1.txt
I need to extract the string file1.txt from temp.txt and store the value in a variable. I did this using a batch script with the following commands
set "DirPath=C:\folder\"
for /f "tokens=* delims=%DirPath%" %%a in (temp.txt) do echo %%a
I just get the string "xt" output and not file1.txt. What am I doing wrong?
I am assuming that the delimiter is C:\folder\ and that should give %%a as file1.txt
Any help will be greatly appreciated.
FOR command - help please
Moderator: DosItHelp
Re: FOR command - help please
Hi kabalman,
the delims is a list of single characters, so you get "C" ":" "\" "f" "o" ...
So nearly all of your string seems to be a delimiter.
try to use
Then you use the standard delims (space and tab).
In %%a is "C:\folder\file1.txt
and %%~nx stands for
n - name of he file
x - extension of the file
jeb
the delims is a list of single characters, so you get "C" ":" "\" "f" "o" ...
So nearly all of your string seems to be a delimiter.
try to use
Code: Select all
for /f "tokens=*" %%a in (temp.txt) do echo %%~nxa
Then you use the standard delims (space and tab).
In %%a is "C:\folder\file1.txt
and %%~nx stands for
n - name of he file
x - extension of the file
jeb
Re: FOR command - help please
Why so complicated?
n is for name and x is for extension
Have a look to the help (for /?) and you will find more options.
Regards
aGerman
[edit]@jeb - da hat wohl einer rechts überholt [/edit]
Code: Select all
for /f "delims=" %%a in (temp.txt) do echo %%~nxa
n is for name and x is for extension
Have a look to the help (for /?) and you will find more options.
Regards
aGerman
[edit]@jeb - da hat wohl einer rechts überholt [/edit]
Re: FOR command - help please
Thanks a lot. That worked absolutely fine.