rename files in a folder with left pad zeros -


i need rename multiple files in folder. file names either 6 digits long or 9 digits long , need left pad file names leading zeros make total of 16 digits long.

for example if file name 123456.jpg should renamed 0000000000123456.jpg , if 123456789.jpg should renamed 0000000123456789.jpg.

maximum length of total digits should 16 digits.

there can 100 or more files in folder.

i tried this, know not code required task. started 1 , need move forward.

@echo off setlocal enableextensions enabledelayedexpansion rem iterate on jpg files: %%f in (c:\documents\pictures\pic\*.jpg) (     rem store file name without extension     set filename=%%~nf     rem add leading zeroes:     set filename=00000000000!filename!     rem add extension again     set filename=!filename!%%~xf     rem rename file     rename "%%f" "!filename!" ) 

i prefer batch script. if not possible, vb script accepted.

based upon stephan's recommendation, have updated code below. code not prefix zeros file name 123456.jpg.

i want add here knowledge on batch script coding limited. code trying initial trial, want , has been mentioned in question script should able prepad zeros irrespective of file name 6 digits long or 9 digits long , make total of 16 digits long. think if code trying starts work, still not looking for.

when run code not anything.

@echo off setlocal enableextensions enabledelayedexpansion rem iterate on jpg files: %%f in (c:\documents\pictures\pic\*.jpg) (     rem store file name without extension     set filename=%%~nf     rem add leading zeroes:     set filename=0000000000!filename!     set filename=!filename:~-16!     rem rename file     rename "%%f" "!filename!"     set filename=!filename!%%~xf     rem rename file     rename "%%f" "!filename!" ) 

updated code converting 6 digits long file name 16 digits long:

@echo off setlocal enableextensions enabledelayedexpansion rem iterate on jpg files: %%f in (c:\documents\pictures\pic\*.jpg) (     rem store file name without extension     set filename=%%~nf     rem add leading zeroes:     set filename=000000000!filename!     set filename=!filename:~-16!     set filename=!filename!%%~xf     rem rename file     rename "%%f" "!filename!" )  

instead of worrying initial length of filename, add enough zeros front of filename , cut resulting string sixteen characters:

... set filename=%%~nf set filename=0000000000000000!filename! set filename=!filename:~-16!%%~xf ... 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -