| Using the Date to name Files, Folders or Directories |
There are so many requests for a way to rearrange the date string in the alt.msdos.batch newsgroup for use in naming files and such that in self defense I have worked to fully address this issue once and for all. I had previously included a method here that didn't work for all country codes, but was independent of the language used in the DOS/Win 9x version. If you want that version it is still available, without comment, as PDate.bat. However, I have recently developed another approach which I believe is as close to being univeral as I will ever be able to accomplish.
|
:: UniPDate.bat - A universal date parsing routine. Returns the date in |
Unfortunately, it is a complicated procedure and I just don't have time to offer an explanation right now. You're welcome to use it as is, or dope out its inner workings on your own. With a bit of tinkering the same approach can be used to parse the TIME string. I have done it, but don't have time to incorporate it here now.To use UniPDate, simply CALL it from your procedure with or without the name of a variable to contain the result as the single command line parameter. If no name is given, the output is returned in the variable DateName. Note that the date is returned in YYYYMMDD format whether the standard format for your system configuration is MM-DD-YYYY, DD/MM/YYYY, DD-MM-YYYY or even DD,MM,YYYY. It can easily be altered to return any part or each part of the date in separate variables. This exercise is left to the student.
I recently had occasion to revisit this procedure and significantly revise and compress it. However, this particular version does not incorporate the rearrangement of the parts of the date. To do that, replace the underscore chacrater near the end of the code with a space or other DOS delimiter character and use the approach illustrated in UniPDate to reassemble the pieces in the manner desired.
Obviously, though much shorter, the procedure is also much more difficult to understand (and to explain. Sorry, I can't really take the time to unpack and describe all of its features and techniques.
You do need to know that the procedure takes two optional arguments, a variable name to store the result into (default is DateName, like UniPDate) and a second argument of almost any non-delimiter, which when present flags the desire to replace the normal hyphen or slash in the date string with the underscore character.
|
:: UniDateB.bat - A way to store today's date into the environment |
And to be complete, here is a similar Time parsing routine.
|
:: UniTimeB.bat - A way to parse and store the current time string into the environment |