1.

Solve : Simple batch file help?!?

Answer»

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.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. Quote from: Fleexy on April 07, 2010, 03:29:37 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.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.  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!
)
Quote from: Dusty on April 08, 2010, 02:56:11 AM
As you are desperate here's an untested script, hope it helps:

WOW
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 :]


Discussion

No Comment Found