Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: what is wrong with this  (Read 3195 times)

0 Members and 1 Guest are viewing this topic.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
what is wrong with this
« 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



Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: what is wrong with this
« Reply #1 on: March 10, 2010, 05:40:11 PM »
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..
)
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
Re: what is wrong with this
« Reply #2 on: March 10, 2010, 05:45:02 PM »
worked to a extent
file name is %b.txt
data is %c



Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: what is wrong with this
« Reply #3 on: March 10, 2010, 05:49:07 PM »
It is.

%? on the command prompt is %%? in a batch file. (? being a single-letter wildcard)
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
Re: what is wrong with this
« Reply #4 on: March 10, 2010, 05:50:32 PM »
no the name of the file created was %b etc.



Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: what is wrong with this
« Reply #5 on: March 10, 2010, 05:54:10 PM »
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..
)
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
Re: what is wrong with this
« Reply #6 on: March 10, 2010, 05:56:10 PM »
thank you



Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: what is wrong with this
« Reply #7 on: March 10, 2010, 06:01:45 PM »
Any time!
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.