Tamseyc
Tamseyc

Reputation: 445

Moving files from one directory and appending a date to the file name to another directory

I have a batch script as follows

move /Y E:\Scripts\*.sql E:\Scripts\OBIEE

Lets say in E:\Scripts I have a file insert.sql I want to save it in E:\Scripts\OBIEE as insert_31102012.sql where 31102012 is the current date 31 Oct 2012.

Any Ideas?

Upvotes: 0

Views: 2389

Answers (1)

Rick
Rick

Reputation: 610

This will append the date (_YYYYMMDD) to all .SQL files in the E:\Scripts\ directory, then move them to the E:\Scripts\OBIEE\ subfolder.

@echo off
cd E:\Scripts\
set cur_yyyy=%date:~10,4%
set cur_mm=%date:~4,2%
set cur_dd=%date:~7,2%
for /f %%f in ('dir /b *.sql') do (
rename %%f %%~nf_%cur_yyyy%%cur_mm%%cur_dd%%%~xf
move %%~nf_%cur_yyyy%%cur_mm%%cur_dd%%%~xf ./OBIEE/
)

Upvotes: 2

Related Questions