[Solved] Remove Leading zeros from a txt file

Score
0
Vote Up
February 9, 2012 at 06:24:15 Pacific
Specs: Windows XP

I have file that is a list of videos files that i have to move from on folder to another every day, but the list has leading zeros on the name.

Here what i have so far:

Result.txt - this is file that has my list in
00005215040
00014474158
00014474176
00014474157
00000963066


File mover.bat

@echo off

for /F "tokens=*" %%a in (Result.txt) do (
if exist "c:\input\%%a.mpg" copy "c:\input\%%a.mpg" "c:\output\%%a.mpg"
)
pause


but that when i run in to a issue my files don't have the leading zeros in there file name.

thank for any help.


Jump to Best Answer ↓   Report •


#1
Vote Down
Score
0
Vote Up
February 9, 2012 at 07:48:25 Pacific

Best Answer

@echo off
setlocal EnableDelayedExpansion
for /F "tokens=*" %%a in (Result.txt) do (
  set row=%%a
  set num=
  for /L %%j in (0 1 10) do (
    if "!row:~%%j,1!" neq "0" if not defined num set num=!row:~%%j!
  ) 
  if exist "C:\input\!num!.mpg" copy "C:\input\!num!.mpg" "C:\output" > nul
)
pause

Please, try to post in a more correct English since what you wish looks quite confusing.

Reply ↓  Report •

#2
Vote Down
Score
0
Vote Up
February 9, 2012 at 08:56:24 Pacific

Thanks for you help,

Reply ↓  Report •

Reply to Message Icon Start New Discussion
Related Posts

« exception error in main [Solved] Text files read in direct... »