Solved: Re-order the name of a file. MMDDYY.pdf to YYMMDD.pdf ?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

sternkanz

Thread Starter
Joined
Oct 3, 2008
Messages
21
All in the title. I have a file called 10032008072839AM.pdf

The numbers represent Month-Day-Year-Hours-Minutes-Seconds-AM/PM.

I would like to change this to Year - Month - Day - Hours - Minutes - Seconds - AM/PM so that when I sort it by name it gets sorted chronologically with any other files named in this fashion. I want to do this with a batch script

Could anyone point me in the right direction for this? The end result is basically swapping the first 4 characters of the file name with the second 4 characters of the file name.

Any help highly appreciated.
 

sternkanz

Thread Starter
Joined
Oct 3, 2008
Messages
21
Ahh oops. Forgot to mention I want to do this with a batch script. Hehe.
 
Joined
Apr 7, 2007
Messages
4,910
here ya go

Code:
@echo off
setlocal
for /f "delims=" %%a in ('dir /b /a-d *.pdf') do call :PROCESS "%%~na" "%%~xa"
goto :EOF

:PROCESS
set "var=%~1"
set "ext=%~2"

::extract the first four characters of the filename
call set "a=%%var:~0,4%%"

::extract the second four characters of the filename
call set "b=%%var:~4,4%%"

::rename file
ren "%var%%ext%" "%b%%a%%var:~8%%ext%"
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top