Como adiciono um zero inicial a um lote de nomes de arquivos?
Use o seguinte comando:
for /f %f in ('dir /b *.pdf') do ren "%f" "0%f"
Para usar em um arquivo de lote, substitua %
por %%
:
for /f %%f in ('dir /b *.pdf') do ren "%%f" "0%%f"
Exemplo de uso:
F:\test\test>dir
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test\test
24/06/2016 21:39 <DIR> .
24/06/2016 21:39 <DIR> ..
24/06/2016 21:38 0 000165-CityName1.pdf
24/06/2016 21:38 0 000166-CityNameLonger2.pdf
2 File(s) 0 bytes
2 Dir(s) 1,769,011,425,280 bytes free
F:\test\test>for /f %f in ('dir /b *.pdf') do ren "%f" "0%f"
F:\test\test>ren "000165-CityName1.pdf" "0000165-CityName1.pdf"
F:\test\test>ren "000166-CityNameLonger2.pdf" "0000166-CityNameLonger2.pdf"
F:\test\test>dir
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test\test
24/06/2016 21:40 <DIR> .
24/06/2016 21:40 <DIR> ..
24/06/2016 21:38 0 0000165-CityName1.pdf
24/06/2016 21:38 0 0000166-CityNameLonger2.pdf
2 File(s) 0 bytes
2 Dir(s) 1,769,011,425,280 bytes free
Leitura Adicional