1.

Solve : Batch file to rename folder to date AND time not OR time?

Answer»

How can this be done?

I tried this but I doesn't work for some reason. I am really shooting int he dark here sorry...

Code: [Select]@echo off
for /f "tokens=1-3 delims=/- " %%a in (%date%) do set XDate=%%a-%%b-%%c
for /f "tokens=1-3 delims=: " %%a in (%time%) do set Xtime=%%a.%%b.%%c
xcopy "D:\My Documents\UPENN\Class Files\Calculus 114-003" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Calculus 114-003" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Meam 110-001" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Meam 110-001" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Chemistry 101-006" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Chemistry 101-006" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Color Photography" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Color Photography" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Meam 147-101" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Meam 147-101" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Chemistry 053-001" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Chemistry 053-001" /E /V /H /Y /s /i
echo ----------Backup COMPLETE----------
pauseWhen you say it "doesn't work", what exactly do you mean? That is one of the biggest errors you can make on a help forum (saying just "it doesn't work".) What doesn't happen? What should happen? We shouldn't have to decipher your code and try to work out what you wanted it to do.
Oh sorry forgot that small BIT of info, lol. Theoretically I would liek it to rename that folder to Class Files dd-mm-yyyy hh:mm:ss.ss

Does that make sense? Currently all it does is create a folder called Class Files that is empty (even though there are files it should be copying and the /i tag in xcopy should make it create the directory if it does not exist). Ideally I am trying to make a backup feature that will create a new folder every time it is run that is named according to the date and time.Is there seriously no one who can point me in the RIGHT direction? THis isn't exactly a complicated task.Assuming the parsing is correct, date and time need to be literals:

Code: [Select]@echo off
for /f "tokens=1-3 delims=/- " %%a in ("%date%") do set XDate=%%a-%%b-%%c
for /f "tokens=1-3 delims=: " %%a in ("%time%") do set Xtime=%%a.%%b.%%c
xcopy "D:\My Documents\UPENN\Class Files\Calculus 114-003" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Calculus 114-003" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Meam 110-001" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Meam 110-001" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Chemistry 101-006" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Chemistry 101-006" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Color Photography" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Color Photography" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Meam 147-101" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Meam 147-101" /E /V /H /Y /s /i
xcopy "D:\My Documents\UPENN\Class Files\Chemistry 053-001" "D:\My Documents\UPENN\Backups\Class Files %XDate% %XTime%\Chemistry 053-001" /E /V /H /Y /s /i
echo ----------Backup COMPLETE----------
pause

I seem to recall from the old days that the switches for xcopy had to be placed physically before the file names. Maybe that's changed. I think the attrib command was the same way.

Did you read the prior posts? You never did state the symptoms of "I tried this but I doesn't work for some reason"

Quote from: ryank on September 16, 2008, 03:29:35 PM

Oh sorry forgot that small bit of info, lol. Theoretically I would liek it to rename that folder to Class Files dd-mm-yyyy hh:mm:ss.ss

Does that make sense? Currently all it does is create a folder called Class Files that is empty (even though there are files it should be copying and the /i tag in xcopy should make it create the directory if it does not exist). Ideally I am trying to make a backup feature that will create a new folder every time it is run that is named according to the date and time.

^^^^^^^^^

Uh yeah I read the prior posts, did you?

Your advice is not very descriptive or helpful. I already know that the xcopy commands are formatted properly I just don't know why the variables don't work. Flags for xcopy do go AFTER the destination and source. I have tried this in other files and it works fine.ryank:

Strike 1: Bumping/whining

Quote from: ryank
Is there seriously no one who can point me in the right direction? THis isn't exactly a complicated task.

Strike2: Complaining/criticising helpfully intended answers

Quote from: ryank
Uh yeah I read the prior posts, did you?

Your advice is not very descriptive or helpful.

Whether or not you commit a 3rd strike, people are only human, and may be seriously demotivated by your attitude.






Quote from: SIDEWINDER on September 17, 2008, 12:33:18 PM
Assuming the parsing is correct, date and time need to be literals:

Code: [Select]@echo off
for /f "tokens=1-3 delims=/- " %%a in ("%date%") do set XDate=%%a-%%b-%%c
for /f "tokens=1-3 delims=: " %%a in ("%time%") do set Xtime=%%a.%%b.%%c

Quote
Uh yeah I read the prior posts, did you?

Indeed I did! Did you make the date and time literals? Hint: put quotes around the date and time variables.

Note: The quotes will allow the date and time strings to be parsed. Not knowing the format of your system date and time, you may have to adjust the tokens= clause.

Quote
Your advice is not very descriptive or helpful.

Criticism acknowledged. You do know that we have a money back guarantee. If you could document your CH expenses, I'll be glad to send them to Patio, the CH cashier/dentist/barkeeper. Quote from: Sidewinder on September 18, 2008, 03:48:31 AM
Criticism acknowledged. You do know that we have a money back guarantee. If you could document your CH expenses, I'll be glad to send them to Patio, the CH cashier/dentist/barkeeper.

In fact if people aren't completely happy, we refund double their money.

I think I can see where his problem might be, but I've been suddenly called away before I can post it...Hi RyanK. If I understand you question, you basically want to rename a file or folder by putting a timestamp (having both the date and the time) into the name? If so, please play around with the code below. (I modified it based on code I found on another site). Hope this helps solve your problem.

Basically it uses the DOS "move" command to rename the same file or folder in place.

Code: [Select]
REM --> Renames a File or Folder with a TimeStamp. Keeps Folder Contents Intact.
REM ---------------------------------------
echo off
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yyyy-mm-dd__hh.mm.ss=%date:~10,4%-%date:~4,2%-%date:~7,2%__%hh%.%time:~3,2%.%time:~6,2%---%date:~-0,3%
set myDate01=%date:~10,4%-%date:~4,2%-%date:~7,2%
set myDate02=%date:~10,4%-%date:~4,2%-%date:~7,2%__%hh%.%time:~3,2%.%time:~6,2%
echo on

move tempZip.zip LogArchive%yyyy-mm-dd__hh.mm.ss%.zip
move tempFile.txt tempFile%yyyy-mm-dd__hh.mm.ss%.txt
move tempFolder tempFolder%yyyy-mm-dd__hh.mm.ss%
move testFile01.txt testFile01%myDate01%.txt
move testFile02.txt testFile02%myDate02%.txtDayneKnight, did you WRITE that yourself, or copy it? How do you know the OP uses US date format and not another one? How would he alter your code for that?


Discussion

No Comment Found