1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by sternkanz, Oct 3, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. sternkanz

    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.
     
  2. ShadowProwler420

    ShadowProwler420

    Joined:
    Jun 20, 2007
    Messages:
    317
    Right click on the file name and choose Rename then rename it as you see fit. ;)
     
  3. sternkanz

    sternkanz Thread Starter

    Joined:
    Oct 3, 2008
    Messages:
    21
    Ahh oops. Forgot to mention I want to do this with a batch script. Hehe.
     
  4. devil_himself

    devil_himself

    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%"
    
     
  5. sternkanz

    sternkanz Thread Starter

    Joined:
    Oct 3, 2008
    Messages:
    21
    Thank you so much! This worked perfectly. You guys are awesome.

    :)
     
  6. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/755775

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice