|
|
|
Naming directory with current date
|
Original Message
|
Name: jasmine
Date: November 5, 2003 at 11:47:29 Pacific
Subject: Naming directory with current dateOS: Windows XPCPU/Ram: Pentium 4 and 1 GB RAM |
Comment: I am taking backups of my files everyday and I am using a batch file to do this. Currently it is being copied to the same folder and gets overwritten. I don't want this to get overwritten and want to be able to create folders with the current date appended to it and store these for a period of time, for example folder test_20031105. Is this possible to do in the DOS batch file? Also I would like to zip the backup files, how can I do this in the batch file?
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: IVO
Date: November 5, 2003 at 14:10:35 Pacific
Subject: Naming directory with current date |
Reply: (edit)To create a directory with the current date use the following (based upon the system XP variable %Date%) MD TEST_%Date:~-4,4%%Date:~-10,2%%Date:~-7,2% I assume you use the US date format (MMDDYYYY) otherwise change the relative Date element position (%Date:....%). To zip the files is possible, but the exact format of the command is related to the software you currently use to compress (WinZip, PowerArchiver and so on...)
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: dtech10
Date: November 5, 2003 at 14:12:24 Pacific
Subject: Naming directory with current date |
Reply: (edit)Hi jasmine Try Sometime like this @echo off Rem Get Day,Mth & Year from %Date% set Day=%Date:~0,2% set Mth=%Date:~3,2% set Yr=%Date:~6,4% md test_%Yr%%Mth%%Day%
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: jasmine
Date: November 7, 2003 at 14:46:54 Pacific
Subject: Naming directory with current date |
Reply: (edit)Thanks so much! IVO's solution worked. I tried using dtech10's code into a batch file and it was not successful. IVO,I use Winzip for compression. Can you let me know what command I should use?
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: dtech10
Date: November 8, 2003 at 14:17:19 Pacific
Subject: Naming directory with current date |
Reply: (edit)Hi Jasmine I pasted the text from the above item into notepad and saved it as a batch file and it worked ok for me. I'm using WinXP Pro but I would'nt have throught take would make a difference. Anyway IVO's solution is much neater.
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: jasmine
Date: November 10, 2003 at 13:09:39 Pacific
Subject: Naming directory with current date |
Reply: (edit)dtech10, I tried again and it worked now. I must have made a mistake earlier. Thanks to you both.
Report Offensive Follow Up For Removal
|
|
Response Number 7
|
Name: Kemet
Date: November 11, 2003 at 17:09:58 Pacific
Subject: Naming directory with current date
|
Reply: (edit)IVO, Could you explain what ~-(number) represents in the string? TEST_%Date:~-4,4%%Date:~-10,2%%Date:~-7,2% Thanks Kemet
Report Offensive Follow Up For Removal
|
|
Response Number 8
|
Name: IVO
Date: November 12, 2003 at 01:48:21 Pacific
Subject: Naming directory with current date |
Reply: (edit)Hi Kernet, the :~ means you want to refer to the substring embedded in the source variable, according to the syntax %Var:~Off,Lgt% where Off is the offset starting from 0 and Lgt the size of the substring you want to extract. If the offset is negative (-), the offset is computed from the end of the string. So the first %Date:... means select the substring in Date that is located at the last four positions (in other words the last four characters). I leave you to interpret the other two substrings. Why did I process the %Date% backward? To get compatibility between NT/2K and XP Date format, as XP omits to return the day of week. Parsing as I do gives invariance respect to the operating environment. Anyway to know more type Set /? at command prompt (Win NT/2K/XP required).
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|