Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide 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.

30 Jun 2011   #1
SpiritKing

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
.

30 Jun 2011   #2
Seeliewight

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
30 Jun 2011   #3
richnrockville

Windows 7 Pro 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.




Thread Tools





Similar help and support threads
Thread Forum
How to Create a Batch file for last logged on for a remote use
So I am looking to create some kind of batch file or script where I can click on it....it asks for the machine name, I enter it and then it displays the last logged on user. The following command " wmic /NODE:"computername" computersystem get Username" gives me the desired results but I am...
Network & Sharing
Need help to create batch file for IE with following settings
I am new here and wanted some help. I wanted to know if I can do some internet explorer setting using batch file. Settings would be like this A - Home page - about:blank A.1 - Browsing history - marked on delete browsing history on exit. A.1.1 - Settings - enables radio button (Every time...
Chillout Room
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Is it possible to create a windows batch file to do this?
I generally run windows aero theme across all four monitors which i am happy with. However when i run a music app called cubase 5, i hear all sorts of squeaks and glitches when i simply move my cursor around the screen. The problem resolves itself when i switch to the standard windows classic...
General Discussion
How to create a current date folder using batch file?
Hi I am using following batch file for cleaning the desktop and also for taking backup of desktop: @echo off set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% mkdir "%USERPROFILE%\My Documents\backup\%curr_date%_backup"
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion

Our Sites

Site Links

About Us

Find Us

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

All times are GMT -5. The time now is 15:38.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App