Computer Hope
Microsoft => Microsoft DOS => Topic started by: mat123 on March 10, 2010, 05:34:53 PM
-
what is wrong with this code
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a %%b %%c in (test.txt) do (
set newf=%%a
set newf2=%%b
set newf3=%%c
md "!newf!
cd "!newf!
echo "!newf3!" > "!newf2!.txt"
cd..
)
input
test1 test tset
test2 teste etset
test3 tester retset
output nothing
desired output
3 folders called test 1-3
in each folder file called test.txt teste.txt tester.txt
in file tset.txt etset retset
-
A couple issues:
1. If delims is set to "" (nul) then there will be no other tokens.
2. Only the FIRST token name is said in the command.
This would be your code:
@echo off
setlocal enabledelayedexpansion
for /f "delims= " %%a in (test.txt) do (
md %%a
cd %%a
echo %%c > %%b.txt
cd..
)
-
worked to a extent
file name is %b.txt
data is %c
-
It is.
%? on the command prompt is %%? in a batch file. (? being a single-letter wildcard)
-
no the name of the file created was %b etc.
-
Oh, what a silly mistake. Here is the proper code.
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-3 delims= " %%a in (test.txt) do (
md %%a
cd %%a
echo %%c > %%b.txt
cd..
)
-
thank you
-
Any time!