Windows 7 Forums Search
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows 7. The Windows 7 forum also covers news and updates and has an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7 - Batch file to create a folder with name of the time.

 
06-30-2011   #1


Windows 7 Home Premium 64 Bit
 
 

Batch file to create a folder with name of the time.

I'm trying to write a batch file that when run creates a folder named "Backup" followed by the time it was created, and then copies files to that folder.

When I run

md "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\"
xcopy /e /v /y "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Server\world" "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\"
pause

It creates a folder named the date it was created and places the folders in it. How do I make it so the folder is named the time instead of the date?

My System SpecsSystem Spec
06-30-2011   #2


Windows 7 Ultimate x64 SP1
 
 


you could do something like the below.
*disclaimer*: I am a fairly decent UNIX shell script programmer, but I suck at Windows programming. I did NOT test this out, but it should give you the general idea.

set SOURCEFOLDER="C:\Master"
set BACKUPTIME=%TIME%
set BACKUPFOLDER="C:\blah\Backup %BACKUPTIME%"

md "%BACKUPFOLDER%"
xcopy foo "%SOURCEFOLDER%" "%BACKUPFOLDER%"
My System SpecsSystem Spec
06-30-2011   #3


Windows 7 Ultimate x64 SP1
 
 


Quote   Quote: Originally Posted by SpiritKing View Post
I'm trying to write a batch file that when run creates a folder named "Backup" followed by the time it was created, and then copies files to that folder.

When I run

md "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\"
xcopy /e /v /y "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Server\world" "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\"
pause

It creates a folder named the date it was created and places the folders in it. How do I make it so the folder is named the time instead of the date?

Welcome to the windows 7 forums.

set TIMEST=%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2%
This will remove the : and spaces from time and concatenate it together
to give you %timest%


One problem with using the time and date is that the format for time can have
:'s in it and directory or file names don't accept the colon.

by stripping out the : you can make a real file or directory name.

the same goes with the date when it is less than 10 on the day or month.

the date can have / marks in it and/or spaces which requires removal.

this does them both.

set DATEST=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

Execute it and then echo %datest% and the output will be all numbers showing the numeric date and - then the number time.

Give it a shot

rich
My System SpecsSystem Spec
.


Reply

 Batch file to create a folder with name of the time. problems?



Thread Tools



Similar Threads for: Batch file to create a folder with name of the time.
Thread Forum
batch file open file for program in the startup folder General Discussion
Solved How to create a current date folder using batch file? General Discussion
How to create a batch file that will move files based on the file type General Discussion
batch file to create a daily date folder General Discussion
create a popup reminder using batch file General Discussion


All times are GMT -5. The time now is 01:35 AM.



Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30