Hi, I'm a fairly new user.
I have a loop that creates some consecutive Variables.
set 1=Hello
set 2=my name is
set 3=mark, and I
set 4=have a DOS problem
set 5=I'm hoping
set 6=you can help me with
The number of variables created is NOT fixed
At the end of the loop, variable %L% is the last variable number
L could be any Number between 5 and infinity
How do you return the value of the last variable but one?
Eg, for the above, I can return:
5
but I need to return:
I'm hoping
The bigger picture:
The variables are lines from a .txt file created by dir.
What I want to do is return the line that gives the size of the directory, then I need to manipulate that, leaving just the number of bytes (I think I can do that).
What I'm looking to do with this batch file is add up and then compare directory sizes. This is the only way I can think of doing it.
Basic compound variable problem
Moderator: DosItHelp
Re: Basic compound variable problem
You don't need all these variables. Use a simple FOR loop:
You could also process the DIR command directly
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "usebackq tokens=3" %%i in ("your.txt") do (
call set "size=%%x%%"
set "x=%%i"
)
echo %size%
pause
You could also process the DIR command directly
Code: Select all
@echo off &setlocal
for /f "tokens=3" %%i in ('dir /-c "C:\somewhere"') do (
call set "size=%%x%%"
set "x=%%i"
)
echo %size%
pause
Regards
aGerman
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: Basic compound variable problem
for /f "tokens=3" %%a in ('dir /-c "c:\directory"^|find /i "bytes free"') do set sizeinbytes=%%a
Re: Basic compound variable problem
@avery_larry
Do you know where Mark One comes from? Is there a "bytes free" in his DIR output?
Regards
aGerman
Do you know where Mark One comes from? Is there a "bytes free" in his DIR output?
Regards
aGerman
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: Basic compound variable problem
One can hope that they know how to change for their language, and one can also hope that they know how to ask for additional help if this has to work for multiple languages. Besides -- do you know it's token #3 in every language?
AND -- looking at the OP -- I should have warned them that using this method and then adding together multiple directories will only work up to a total of about 2GB because of the limits of DOS math. (Assuming they would use "set /a" to add things before comparing them.)
AND -- looking at the OP -- I should have warned them that using this method and then adding together multiple directories will only work up to a total of about 2GB because of the limits of DOS math. (Assuming they would use "set /a" to add things before comparing them.)
Re: Basic compound variable problem
Of course you're right. The reason for my hint is that I have to do with American settings at work and German settings at home. Thats why I try to avoid "language sensitive" scripts.
But indeed, I cannot guarantee that it even works for Russians, Chinese, Japanese...
Regards
aGerman
But indeed, I cannot guarantee that it even works for Russians, Chinese, Japanese...
Regards
aGerman