September 15th, 2005, 01:10 PM
|
#1 (permalink)
| | Member
Join Date: Apr 2003 Location: VA
Posts: 250
|
I have a batch file on my USB Drive. When I run it, it makes a backup copy of everything that has been updated on the drive onto my hard drive. I want to make the batch file automatically creates a folder with that days date and move the backup copy there. So it would create on folder for today, one folder for tomorrow, etc.
What syntax would I need to throw in there? |
| |
September 15th, 2005, 03:04 PM
|
#2 (permalink)
| | Senior Member
Join Date: Apr 2002 Location: TechIMO
Posts: 539
|
I found this online:
Here is the website, so the author gets his credit: http://www.tech-recipes.com/computer...g_tips956.html Code:
echo on
@REM Seamonkey's quick date batch (MMDDYYYY format)
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%
Just copy this text into a batch file; run the batch file; In dos, change to the directory of the folder you wish to change; Type "ren foldername %date%"
(Do not type the quotes)Replace foldername with the name of the folder you wish to change the name of.
__________________
20" iMac 2.16GHz / 1GB RAM / 250GB HDD / 8x DVDRW / OS 10.5
|
| |
September 15th, 2005, 03:23 PM
|
#3 (permalink)
| | Member
Join Date: Apr 2003 Location: VA
Posts: 250
|
Here is what I have so far :
@Echo Off
Echo This Program is for Copying Files.
Echo Used to create backup copy of flash disk
mkdir "F:\Backup"
xcopy /w /d /y /h /e "C:\Documents and Settings\wb277600\Favorites"
"F:\Backup"
Echo Copy complete
Pause
Echo Hopefully this will rename the folder to today's date.
REN "Backup" "%mm%%dd%%yyyy%"
Echo Rename Complete
Pause
Where you see the second ECHO command, followed by (what I think is...) the rename command, I just need the command that will insert the date. |
| |
September 15th, 2005, 03:44 PM
|
#4 (permalink)
| | Senior Member
Join Date: Apr 2002 Location: TechIMO
Posts: 539
|
Tell it to run the batch code above then use REN "Backup" %date%
That should do it. |
| |
September 15th, 2005, 09:21 PM
|
#5 (permalink)
| | Member
Join Date: Apr 2003 Location: VA
Posts: 250
|
That seems like it should work but whenever I run it, I get an error message "The syntax of the command is incorrect". I've tried making a test file and running the command directley from the command prompt but receive the same error.
I've tried several combos like %d%, %date...... |
| |
September 16th, 2005, 02:12 PM
|
#6 (permalink)
| | Senior Member
Join Date: Apr 2002 Location: TechIMO
Posts: 539
|
Hmmm...that's odd. It ran fine for me on 2000. Try copying the code from the website link I provided and add it into a batch. Just make sure you are not adding in the ren command into the batch - that needs to run after the batch is run. |
| |
September 16th, 2005, 02:42 PM
|
#7 (permalink)
| | Member
Join Date: Apr 2003 Location: VA
Posts: 250
|
I finally got it to work, I used the code below which is similar to what you showed me in that link.
Echo Hopefully this will rename the folder to today's date.
Rem Get Day,Mth & Year from %Date%
set Day=%Date:~0,2%
set Mth=%Date:~3,2%
set Yr=%Date:~6,4%
ren "backup" %Day%-%Mth%-%Yr%
Pause
Any idea how to squeeze the time feature in there as well? I've tried this line
set time=%time.....
but I don't know what the put after that.
I'm not batch-file smart. |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | |
Similar Threads | | Thread | Thread Starter | Forum | Replies | Last Post | | Batch File Help | PeterGriffin | General Tech Discussion | 0 | October 28th, 2004 03:52 PM | | Batch File Help | Crackerjack | Applications and Operating Systems | 6 | October 14th, 2003 11:01 AM | | Help with Batch File | PeterGriffin | General Tech Discussion | 3 | October 2nd, 2003 01:41 PM | | batch file help | glue_head | Applications and Operating Systems | 9 | August 29th, 2003 06:44 PM | | Batch file | ribster | Technical Support | 3 | May 12th, 2003 09:53 AM | | Most Active Discussions | | | | | Recent Discussions  | | | | | |