Jump to content

Move a file to a folder then append the file name with the date


Recommended Posts

Posted

I have a folder :

 

G:\stf_info\techs\UNITeDownloads

 

It contains 2 files :

 

Login.csv

Gmail.csv

 

Every day (Monday - Friday) I would like to rename the file to Login010101.csv (010101 being the date!) and move it across to the G:\stf_info\techs\UNITeDownloads\Archive sub folder

 

Is there an easy way to do this? :)

Posted

Batch file as a scheduled task?

 

@echo off

set Source=G:\stf_info\techs\UNITeDownloads

set Target=G:\stf_info\techs\UNITeDownloads\Archive

FOR /f "tokens=1-5 delims=/.:- " %%A in ("%date%") DO (

SET Month=%%A

SET Day=%%B

SET Year=%%C

SET All=%%A%%B%%C

)

 

FOR %%i IN ("%Source%\*.csv") DO ^

COPY "%%i" "%Target%\%%~Ni %All%.csv"

  • Thanks 1
Posted

If you want it in powershell, this should do you

 

$source = "G:\stf_info\techs\UNITeDownloads\login.csv"
$target = "G:\stf_info\techs\UNITeDownloads\Archive"
Move-Item $source ("$target\login{0:ddMMyy}.csv" -f(get-date))

 

and then just setup a scheduled task.

  • Thanks 1
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...