Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to create a batch file to copy files or folders in a specified directory and append the date and time to their names.
Here's my actual code:

@echo off
Set _bpath=T:\Backup\
if [%1]==[] goto :eof
:loop
Set _file=%~n1%
Set _ext=%~x1%
For /f "tokens=1-3 delims=1234567890 " %%a in ("%time%") Do Set "delims=%%a%%b%%c"
For /f "tokens=1-4 delims=%delims%" %%G in ("%time%") Do (
   Set _hh=%%G
   Set _min=%%H
   Set _ss=%%I
   Set _ms=%%J
)
copy %1 "%_bpath%%_file%(%date:/=-% %_hh%h%_min%m%_ss%s)%_ext%"
shift
if not [%1]==[] goto loop

This one works for files only and I could adapt it easily for folders with xcopy /E %1 "%_bpath%%_file%(%date:/=-% %_hh%h%_min%m%_ss%s) but I would like to avoid dealing with two batch files.

So how to copy/rename them indiscriminately (I have try with copy, xcopy and robocopy without success) or how to distinguish them to create two IF branch? (Using %~x1% is too unreliable...)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This might be useful to you, see this question

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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