Quick batch file help!

Soldato
Joined
31 Oct 2003
Posts
4,577
Location
Derby, UK
Afternoon guys.

I'm looking for a bit of help in creating a batch file, which I dont really know much about.

All I need the batch file to do is copy an excel file (which it will be in the same directory as) and move it to another folder, but adding the date and time to the file name at the same time.

Im sure this is relatively simple to do but after having trawled the net and not being very succesful, I thought someone here could enlighten me!

Thankyou for any help!

Rob
 
:/

Cant even get the copy bit to work! Its going to be a long day! Any more advise?! :)

Edit: Scrap that I was being an idiot, so i can copy the file into the directory I want, but thats about it!
 
Last edited:
PHP:
@echo off

REM Read date
FOR /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do ( 
	Set Day=%%A
	Set Month=%%B
	Set Year=%%C
)

REM Read time
FOR /F "tokens=1,2,3,4 delims=:." %%A in ("%time%") do ( 
	Set Hour=%%A
	Set Minute=%%B
	Set Second=%%C
	Set Millisecond=%%D
)

REM Create backup folder?
IF NOT EXIST Backup MKDIR Backup

REM copy all .xls files
FOR /f "tokens=*" %%G IN ('dir /b /O:D *.xls 2^>NUL') DO @(
	copy "%%G" "backup/%%G_%year%-%month%-%day%_%hour%-%minute%-%second%-%millisecond%.xls"
)

Here you go. An extension of a backup batch script I created for work a while ago. Have fun :p.
 
Back
Top Bottom