Dos script error: identical result after some iterations

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
auberns
Posts: 1
Joined: 06 Mar 2013 12:18

Dos script error: identical result after some iterations

#1 Post by auberns » 06 Mar 2013 12:23

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

mfm4aa
Posts: 70
Joined: 13 Feb 2013 14:02
Location: Europe

Re: Dos script error: identical result after some iterations

#2 Post by mfm4aa » 06 Mar 2013 12:49

This can happen, if your filename contains more than 30 characters because you cut it.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Dos script error: identical result after some iterations

#3 Post by foxidrive » 06 Mar 2013 23:06

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.

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

Post Reply