-1

Find:

"Text (Y.m.d) - XXX - YYY - Name.ext"

Replace:

"Text - XXX - YYY - (d.m.Y) - Name.ext"

Where:

Text is static across all files upper and lowercase letters only

XXX three decimal interger with up to two leading zeroes different across all files (eg. 014)

YYY three decimal interger with up to two leading zeroes different across all files

(d.m.Y) and (Y.m.d) the date d= number day (with leading zero if <10) m= number of the month (with leading zero <10) Y= four digit year (eg. (07.12.2014) (different across all files and to be changed))

Name: The actual name of the file contains only upper- and lower-case letters and punctuation and maybe & (eg. HTML5 and PHP)

2 Answers2

0

A batch file with code

@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%F in ('dir "C:\Temp\* (????.??.??) - ??? - ??? - *.ext" /B') do (
   set "FileName=%%~nxF"
   set "Begin=!FileName:~0,5!"
   set "Year=!FileName:~6,4!"
   set "Month=!FileName:~11,2!"
   set "Day=!FileName:~14,2!"
   set "Middle=!FileName:~18,14!"
   set "End=!FileName:~32!"
   ren "%%~dpnxF" "!Begin!!Middle!(!Day!.!Month!.!Year!) - !End!"
)
endlocal

renames a file with name

Text (2014.09.07) - 014 - 205 - Name.ext

in directory C:\Temp to

Text - 014 - 205 - (07.09.2014) - Name.ext

Open a command prompt window and enter set /? to get help about syntax for extracting parts from a string value of an environment variable as used here. Enter also for /? and dir /? for help about the 2 other commands used in this batch code.

By the way: Shareware file manager Total Commander has a feature called multi-rename tool which makes it possible to rename files quickly without any batch coding skills within 30 seconds, see the screenshot about multi-rename tool and tutorial for question rename a lot of files?

Mofi
  • 46,139
  • 17
  • 80
  • 143
0

This assumes the Text prefix does not contain -, (, or ). Note that TOKENS skips the 3rd token (the space between ) and -).

@echo off
for /f "eol=: delims=" %%F in (
  'dir /b /a-d "* (??.??.??) - ??? - ??? - *"'
) do for /f "eol=: delims=()- tokens=1,2,4,5*" %%A in ("%%F") do (
  for /f "delims=. tokens=1-3" %%X in ("%%B") do (
    ren "%%F" "%%A-%%C-%%D (%%Z.%%Y.%%X) -%%E"
  )
)

The code can be made to ignore files that contain problem characters in Text by adding FINDSTR

@echo off
for /f "eol=: delims=" %%F in (
  'dir /b /a-d "* (??.??.??) - ??? - ??? - *"^|findstr /x "[^(-)]*(..\...\...) - ... - ... -.*"'
) do for /f "eol=: delims=()- tokens=1,2,4,5*" %%A in ("%%F") do (
  for /f "delims=. tokens=1-3" %%X in ("%%B") do (
    ren "%%F" "%%A-%%C-%%D (%%Z.%%Y.%%X) -%%E"
  )
)
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • 1
    I didn't test this - is the extra double quote in the `delims=` section legit? `"eol=: delims="()- tokens=1,2,4,5*"` – foxidrive Sep 07 '14 at 19:41