Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Shifting variables in for /f
Name: iborg Date: July 19, 2009 at 23:15:29 Pacific OS: Windows XP Subcategory: Software Problems
Comment:
Hi, I need help with this one. I want to shift variables in a for /f loop. For example for /f "tokens=1,2,3,4,5,6,7,8,9 delims=:" %%a in ('@echo %trk%') do echo %%a %%b %%c %%d %%e %%f %%g %%h %%i (%trk% may contains something like 1:2:4:6:7:8:12) So instead of writing code to handle all the %%a to %%i variables I prefer to use a shift like method to process %%a only. This also helps to avoid extra code to handle how many variables have data inside.
Name: ghostdog Date: July 19, 2009 at 23:53:19 Pacific
Reply:
here's a vbscript. Although its entirely up to you, i would recommend you learn about it, if you want to do scripting/batching on Windows.
strData = "1:2:4:6:7:8:12"
ArrData = Split(strData,":") 'split on ":"
For i=LBound(ArrData) To UBound(ArrData)
'Print out the elements.
WScript.Echo ArrData(i)
Next
Name: iborg Date: July 19, 2009 at 23:59:04 Pacific
Reply:
Thanx for the vbscript. The thing is that although i know vbscript (and as you demonstrated its a nobrainer to do the job) this specific script must be written in dos batch :-((
0
Response Number 3
Name: Judago Date: July 20, 2009 at 00:19:49 Pacific
Reply:
What about:
for %%a in (%trk::= %) do (
REM your stuff with %%a
)
If you variable contains <, >, |, ^, ;, =, a comma or tab it won't work as expected, since you only have numbers it shouldn't be a problem.
0
Response Number 4
Name: iborg Date: July 20, 2009 at 00:29:16 Pacific
Reply:
Awesome!!! That did the job smoothly! Thanx a lot Judago!
Summary: I'm having some problems with the FOR /F command. I've been trying to read from a file which is fine, problem is whenever I try and do any sort of arithmatic using the %% variables I seem to get weird...
Summary: In my office we use CSV files to create users. In this csv file we enter the users information like his name, account, etc. Every branch of the company has different groups every users needs, so ever...
Summary: I need to run multiple DO commands in my FOR /F loop. for /f "options" %%a in (fileset.txt) do (fc /b /c %source%\%%d if not %errorlevel%==0 call error.bat) The file compare happens but then I get a l...