
Re: removing dots from filenames
mcranmer wrote:
I know that the order is always day, month, year.
The naming convention of the files if fairly simple. Examples are:
12_PPRb_B7X_220212.txt
12_RP1_B7S_270211.txt
12_RP2_B7S_270211.txt
12_RP3_B7S_270211.txt
12_RP3_B7V_270211.txt
12_RP4_B7S_270211.txt
2P_PPN_20.07.11.txt
773_PPN_06.10.2011.txt
9O_PPN_08.08.11.txt
A9D_PPN_17.02.12.txt
A9E_PPN_17.02.12.txt
A9F_PPN_17.02.12.txt
A9G_PPN_17.02.12.txt
A9H_PPN_17.02.12.txt
B68_PPN_17.02.12.txt
C3G_PPN_24112011.txt
I am thinking the problem in terms of [...] replacing "\d{6,8}" (in regex terms) with todays date.
Does this make sense?
Can you confirm that you want to strip out every date and replace it with today's date?
If so then the code below will help.
EDIT: It now counts the filename length so should be quicker.
Code:
:: renames and replaces from the last "_" in a filename with _%d8%
@echo off
set d8=20120301
for /f "delims=" %%b in ('dir "*.txt" /b') do call :next "%%b"
pause
GOTO:EOF
:next
echo processing %1
pushd "%~dp1"
set "name=%~nx1"
set "num=0"
set "found="
:countlength
set /a num=num+1
call set "name2=%%name:~%num%,1%%"
if not "%name2%"=="" goto :countlength
:loop
set /a num=num-1
if %num% lss 0 goto :EOF
call set "name2=%%name:~%num%,1%%"
if "%name2%"=="_" set /a found=num-1
if not defined found goto :loop
call ren %1 "%%name:~0,%num%%%_%d8%%~x1"
popd
goto :EOF