| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 47987 | 2004-08-11 05:07:00 | Batch file to insert date | Spartacus (3313) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 260390 | 2004-08-11 05:07:00 | I read somewhere about a substitution you could use in a batch file for inserting the date (or various other entities) into a file name for example. Now that I need that functionality, I can't remember where to find it... Specifically, I would like to run a batch file that creates a directory whose name is the current date and time, and then copies three folders into the new directory. Any ideas appreciated! S |
Spartacus (3313) | ||
| 260391 | 2004-08-11 07:31:00 | --- option 1 ------ make a txt file and put in date > date . txt close it and change the name from what ever to date . bat this will replace the date inside the file each time to click onto date . bat --- option 2 ------ make a txt file and put in date >> date . txt close it and change the name from what ever to date . bat this will replace the date inside the file each time to click onto date . bat PROBLEM: There is just one problem it will stop and ask you for a new date, not sure how you could fix that |
Earnie Moore (5918) | ||
| 260392 | 2004-08-11 08:35:00 | >> From: 43S,172E So where are you Spartucus? I figure you're somewhere in the middle of the South Island? www.mapquest.co.uk 8.qa72u6%28n0072u6%28l%241w-u.wf7%3bxcx5sf7.grfe%7cs%24jdvnd%7cC2j%2fCw8%2bFj7 cyv,%2b.qa%2b2%2b6%24%2b%2butl%2b6%2b2&pcat=]I hope this link works[/url] :D Mike. |
Mike (15) | ||
| 260393 | 2004-08-11 08:52:00 | Somehow you need to tell your PC (maybe in the OS somewhere) to format the date with '-' rather than '/' (eg 11-08-2004 rather than 11/08/2004) then this would work: set %date%=date md %date% I'll keep looking. Mike. |
Mike (15) | ||
| 260394 | 2004-08-11 08:57:00 | > Somehow you need to tell your PC (maybe in the OS > somewhere) to format the date with '-' rather than > '/' (eg 11-08-2004 rather than 11/08/2004) The same would apply for time, but in the case of the colons rather than slashes. Mike. |
Mike (15) | ||
| 260395 | 2004-08-11 09:03:00 | > > Somehow you need to tell your PC (maybe in the OS > > somewhere) to format the date with '-' rather than > > '/' (eg 11-08-2004 rather than 11/08/2004) > > The same would apply for time, but in the case of the > colons rather than slashes. If you're running this batch file from within Windows, change your regional settings to display the date and/or time differently, and this batch file should work (did for me) set %date%=date md "%date%" cd "%date%" The quotes are important. Mike. |
Mike (15) | ||
| 260396 | 2004-08-11 22:10:00 | >> From: 43S,172E >So where are you Spartucus? I figure you're somewhere in the middle of the >South Island? Close enough - must have been my rounding! :D It's Chch I appreciate your efforts re the batch file - I'd prefer to not have to change the display settings (it's not going onto my pc), but it's given me a good starting point. I'll just have to concoct a little parsing code to change the /'s to something more acceptable. Thanks again, S |
Spartacus (3313) | ||
| 260397 | 2004-08-11 23:16:00 | Got it! (he says excitedly) - it now creates a directory such as 2004-08-12 10h14m25 depending of course on the current date and time. Code as follows: @ECHO OFF FOR /F "TOKENS=2-4 DELIMS=/ " %%a IN ("%date%") DO SET dd=%%a&SET mm=%%b&SET yy=%%c FOR /F "TOKENS=1-3 DELIMS=:." %%a IN ("%time%") DO SET hh=%%a&SET tt=%%b&SET ss=%%c MD "%yy%-%mm%-%dd% %hh%h%tt%m%ss%" |
Spartacus (3313) | ||
| 260398 | 2004-08-12 02:12:00 | Now set it to music so you can sing it. :D | Graham L (2) | ||
| 1 | |||||