Rename Folders YEAR-MON to YEAR-NN Via Single Command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Rename Folders YEAR-MON to YEAR-NN Via Single Command

#31 Post by Samir » 04 Feb 2015 13:29

foxidrive wrote:
Samir wrote:All the directories are just in 1 level deep, so there's no tree traversing needed per se.


Yep, ta. Saw that earlier.

My code still works for a bunch of folders that are within a single folder.
I thought it would. :)

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Rename Folders YEAR-MON to YEAR-NN Via Single Command

#32 Post by Ben Mar » 03 May 2015 11:02

Since both "REN" and "MOVE" do not support wild card substitution, here is my work-around based on dbenham idea:

Code: Select all

@echo off
setlocal enableDelayedExpansion
set m=0
for %%A in (
  JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
) do for /d %%F in (????-%%A) do (
  set /a m+=1
  set "mm=0!m!"
[b]  set "year=%%F"
  set "yyyy=!year:~0,4!"
  echo ren %%F "!yyyy!-!mm:~-2!"[/b]
)

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Rename Folders YEAR-MON to YEAR-NN Via Single Command

#33 Post by Ben Mar » 08 May 2015 15:40

dbenham wrote:Both of these methods are untested, but unless I have made a silly error, they should work :wink:

Pure batch: Doh :roll: Does not work because wildcard not allowed in REN targe name when renaming folders

Code: Select all

@echo off
setlocal enableDelayedExpansion
set m=0
for %%A in (
  JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
) do for /d %%F in (????-%%A) do (
  set /a m+=1
  set "mm=0!m!"
  ren "%%F" "*-!mm:-2!"
)


Dave Benham


I think a work-around for your above method is like this:

Code: Select all

@echo off
setlocal enableDelayedExpansion
set m=0
for %%A in (
  JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
) do for /d %%F in (????-%%A) do (
  set /a m+=1
  set "mm=0!m!"
  set "folder=%%F"
  set yyyy=!folder:~0,4!
  ren "%%F" "!yyyy!-!mm:~-2!"
)

Post Reply