1

I need to rename multiple files (more than 500) by moving the date format from YYYYMMDD to MMDDYYYY like below. Keep in mind that the dates are already exist and there are already files in the directory with correct format like Filename_08282014.csv. So, _2014 should probably taken as a base to change the incorrect file names. I am trying to find a 1 line DOS command or a batch script but come up empty. Thanks for any help.

LoadAccount_20140915.csv to LoadAccount_09152014.csv

LoadUser_20140719.csv to LoadUser_07192014.csv

. . . . . .

1 Answer 1

0
@echo off
setlocal enableDelayedExpansion
set "root_dir=c:\whatever\"
pushd "%root_dir%"

for %%a in ("load*.csv") do (
    set "filename=%%~na"
    set "filename_ex=%%~nxa"
    set datepart=!filename:~-8!
    set year=!datepart:~0,4!
    set month=!datepart:~4,2!
    set day=!datepart:~6,2!
    set name=!filename:~0,-8!

    ren "!filename_ex!" "!name!!month!!day!!year!.csv"

)

just change the root_dir to the location where your csvs are.This will handle all csvs that start with load but you can change the mask.

2
  • Thanks. That did it. I made 7 copies of the command since there were 7 different files and entered the file names asLoadAccount_2014*.csv and changed them all.......Appreciated the help. Thanks again. I just wish that I know how to mark the question answered and give you a high rating :)
    – Calvin
    Sep 19, 2014 at 18:31
  • @Calvin there should be a thick with "V" shape right under the answer scores .You just need to click on it :)
    – npocmaka
    Sep 19, 2014 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.