Hallo, I have a problem:.
The file A:\text1.txt contains a strings like
? A:\abcd.abc
I have to copy a strings to another file A:\r\xcopy.txt
in the form like this:
XCOPY A:\abcd.abc A:\st\abcd.abc
My solution
FOR /F "tokens=2" %%i in (A:\text1.txt) do (
set oldstr=%%i
set newstr=%oldstr:A:=A:\st\%
echo XCOPY %%i %newstr% 1>> A:\r\xcopy.txt
)
doesn't work; A:\r\xcopy.txt contains now the strings like
XCOPY A:\abcd.abc
What is wrong??http://www.dostips.com/forum/posting.php?mode=post&f=3#
My "for" doesn't work
Moderator: DosItHelp
Re: My "for" doesn't work
enable the delayed expansion and use ! ! instead of % % for variables
add "1>> A:\r\xcopy.txt" at the echo command to make redirect the result to your file.
Note, you will have to remove the last "\" here "%oldstr:A:=A:\st\%"
BTW, what this number "1>> A:\r\xcopy.txt" doing ? .. is it part of your code.
Code: Select all
Setlocal EnableDelayedExpansion
FOR /F "tokens=2" %%i in (A:\text1.txt) do (
set oldstr=%%i
set newstr=!oldstr:A:=A:\st!
echo XCOPY %%i !newstr!
)
pause
add "1>> A:\r\xcopy.txt" at the echo command to make redirect the result to your file.
Note, you will have to remove the last "\" here "%oldstr:A:=A:\st\%"
BTW, what this number "1>> A:\r\xcopy.txt" doing ? .. is it part of your code.
Re: My "for" doesn't work
Or use this:
If you have long filename elements than try this:
Code: Select all
@echo off
FOR /F "tokens=1,*" %%a in (A:\text1.txt) do (
>> A:\r\xcopy.txt echo XCOPY %%b %%~db\st%%~pb
)
If you have long filename elements than try this:
Code: Select all
@echo off
FOR /F "tokens=1,*" %%a in (A:\text1.txt) do (
>> "A:\r\xcopy.txt" echo XCOPY "%%b" "%%~db\st%%~pb"
)
Re: My "for" doesn't work
It's solved!
Thank you for help!
Thank you for help!