hi
I have hundreds of text files in a folder every morning they are sequentially renamed ie 2017120100001.txt (yyyymmdddigit.txt) and
moved to another pc.
my request is
is there a way to sequentially rename these text files and make the batch file save the last seq number
and continue to to rename if its run the next time (ie first run 00001 - 00100, second run 00101 - 00190) and so on
pl help
thanx in advance
txt file renaming
Moderator: DosItHelp
Re: txt file renaming
Going to assume you have some existing code you are already using that you could show us.
Re: txt file renaming
hi
right now its manually done which is really time consuming
right now its manually done which is really time consuming
Re: txt file renaming
steffen did give me a script which worked well and was useful but the old data had to be retained
in the directory for the script to work.
the script is
@echo off &setlocal
set "basename=file"
:: determine the greatest number
set "greatest=10000000"
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /xi "!basename![0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "name=%%~ni"
set /a "current=1!name:~-7!"
if !current! gtr !greatest! set /a "greatest=current"
)
endlocal &set "greatest=%greatest%"
:: rename new files
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /vxi "%basename%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "file=%%i"
set /a "greatest+=1"
setlocal EnableDelayedExpansion
ren "!file!" "!basename!!greatest:~-7!.txt"
endlocal
)
but now the data of the previous day is deleted and the script starts all over again from 00001 .
I need to continue with a new folder with .txt files.
in the directory for the script to work.
the script is
@echo off &setlocal
set "basename=file"
:: determine the greatest number
set "greatest=10000000"
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /xi "!basename![0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "name=%%~ni"
set /a "current=1!name:~-7!"
if !current! gtr !greatest! set /a "greatest=current"
)
endlocal &set "greatest=%greatest%"
:: rename new files
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /vxi "%basename%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "file=%%i"
set /a "greatest+=1"
setlocal EnableDelayedExpansion
ren "!file!" "!basename!!greatest:~-7!.txt"
endlocal
)
but now the data of the previous day is deleted and the script starts all over again from 00001 .
I need to continue with a new folder with .txt files.
Re: txt file renaming
steffen did give me a script which worked well and was useful but the old data had to be retained
in the directory for the script to work.
the script is
@echo off &setlocal
set "basename=file"
:: determine the greatest number
set "greatest=10000000"
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /xi "!basename![0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "name=%%~ni"
set /a "current=1!name:~-7!"
if !current! gtr !greatest! set /a "greatest=current"
)
endlocal &set "greatest=%greatest%"
:: rename new files
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /vxi "%basename%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "file=%%i"
set /a "greatest+=1"
setlocal EnableDelayedExpansion
ren "!file!" "!basename!!greatest:~-7!.txt"
endlocal
)
but now the data of the previous day is deleted and the script starts all over again from 00001 .
I need to continue with a new folder with .txt files.
in the directory for the script to work.
the script is
@echo off &setlocal
set "basename=file"
:: determine the greatest number
set "greatest=10000000"
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /xi "!basename![0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "name=%%~ni"
set /a "current=1!name:~-7!"
if !current! gtr !greatest! set /a "greatest=current"
)
endlocal &set "greatest=%greatest%"
:: rename new files
for /f "delims=" %%i in ('dir /a-d /b *.txt^|findstr /vxi "%basename%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.txt"') do (
set "file=%%i"
set /a "greatest+=1"
setlocal EnableDelayedExpansion
ren "!file!" "!basename!!greatest:~-7!.txt"
endlocal
)
but now the data of the previous day is deleted and the script starts all over again from 00001 .
I need to continue with a new folder with .txt files.