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

Author Topic: Simple batch file help?!  (Read 2406 times)

0 Members and 1 Guest are viewing this topic.

Blackbeard

  • Guest
Simple batch file help?!
« on: April 07, 2010, 12:24:28 PM »
This doesn't work correctly:

@echo off
dir /B *.txt
set X=%1
set Y=%2
echo %X%
echo %Y%
pause > nul

It can't "set" this way so of course it won't "echo". But how do i get it to "set" X equal to the first file that it displays, and Y to the second file it displays?

I know this is simple but i fail to know exactly how to use "for" which is what i think is needed, but I'm not sure.

Fleexy



    Intermediate

  • OW NEXT TIME I SHOULD TURN IT OFF BEFORE SERVICING
  • Thanked: 2
    • Yes
    • Yes
  • Experience: Experienced
  • OS: Windows XP
Re: Simple batch file help?!
« Reply #1 on: April 07, 2010, 03:29:37 PM »
@echo off
dir /B *.txt
set %X%=%1
set %Y%=%2
echo %X%
echo %Y%
pause > nul

I think you need the %s around the variables in the set command.
I love .NET!

Blackbeard

  • Guest
Re: Simple batch file help?!
« Reply #2 on: April 07, 2010, 03:40:21 PM »
set %X%=%1
set %Y%=%2

I think you need the %s around the variables in the set command.

It doesn't work like that
The format i have is correct:
set A=1
set B=2
set C=3
echo %a%+%b%=%c%

The commands i have are not wrong, they simply don't work in the way i have them.

Blackbeard

  • Guest
Re: Simple batch file help?!
« Reply #3 on: April 07, 2010, 10:30:28 PM »
bump

also. let me re articulate the bane of my week.

@echo off
dir /B *.txt
pause > nul

this lists the text file names in the current directory

(Assuming there are 2 txt files in the directory) What i want is so that the first file listed is "set" to something, and the second file is "set" to something else.

help appreciated and desperately needed.  :)

Dusty



    Egghead

  • I could if she would, but she won't so I don't.
  • Thanked: 75
  • Experience: Beginner
  • OS: Windows XP
Re: Simple batch file help?!
« Reply #4 on: April 08, 2010, 02:56:11 AM »
As you are desperate here's an untested script, hope it helps:

Code: [Select]
@echo off
cls
setlocal enabledelayedexpansion


for /f "tokens=*" %%1 in ('dir /b *.txt') do (
    set filename=%%1 & call :increment
   
)
pause > nul
exit /b


:increment
set /anbr+=1
if %nbr% equ 1 ( set X=!filename!
   ) else (
   set Y=!filename!
)

if !nbr! lss 2 (goto :eof
   ) else (
   echo X=!X!  Y=!Y!
)
One good deed is worth more than a year of good intentions.

Blackbeard

  • Guest
Re: Simple batch file help?!
« Reply #5 on: April 08, 2010, 03:43:23 AM »
As you are desperate here's an untested script, hope it helps:

WOW :D
thank you for that

Now i just need to familiarize myself with this new format, a bit advanced for me, but i will work at it.

Much thanx :]