Hello all,
I'm new in this forum. So let me know if I post in the wrong place. I have a script that gives wrong results after a few iterations. Could anybody tell me why the result remain the same after a few iterations (something like 75 iterations). Here is my script:
@echo off
setlocal enabledelayedexpansion
for /f %%G in ('dir /b /o:n *.mp3') do (
call :printVal 30 %%~nG
set CP=!var!
echo !CP!>> run1.txt
)
goto:eof
:printVal
for /L %%a in (1,1,%1) do set zero= !zero!
set var=!zero!%2
set var=!var:~-%1!
goto :eof
Thank you for your responses,
Nicolas
Dos script error: identical result after some iterations
Moderator: DosItHelp
Re: Dos script error: identical result after some iterations
This can happen, if your filename contains more than 30 characters because you cut it.
Re: Dos script error: identical result after some iterations
I modified this to support long filenames and it works ok on 160 files.
We need to know what your input name format is - but the line that resets zero might be needed too or else you could hit the length limit for that variable.
We need to know what your input name format is - but the line that resets zero might be needed too or else you could hit the length limit for that variable.
Code: Select all
@echo off
setlocal enabledelayedexpansion
del run1.txt 2>nul
for /f "delims=" %%G in ('dir /b /o:n *.mp3') do (
call :printVal 30 "%%~nG"
set CP=!var!
echo !CP!>> run1.txt
)
goto:eof
:printVal
set "zero="
for /L %%a in (1,1,%1) do set zero= !zero!
set "var=!zero!%~2"
set "var=!var:~-%1!"
goto :eof