![]() I am still amazed this little trick works. ![]() ![]() The same method could be used for the current time I get a date stamped file, and no special vbscript, or command line program is needed. Which renames our C:\TempZip.Zip to C:\TempZip_20070215.zip Pkzip c:\ImportantFolder\*.* c:\TempZip.zip Lets say I zipped up a folder every night for archival purposes, and wanted a different filename for each day (Not sure if this pkzip syntax is correct, but that is not important for our discussion here) Like this:įor the month we start 7 from the right (Length of Year + Length of Month + 1 Slash)įor the day we start 10 from the right (Length of Year + Length of Month + Length Of Day + 2 Slashes)īringing it all together. If we wanted to get the current year we could start 4 from the end, and 4 in length. I know this might be confusing at first, but you will see what I am talking about. And is the number of characters in the opposite direction of the starting point. If the number is negative it will start from the right. If is positive or zero the substring will start from the left. The :~ substring command works like this: To be safe we can pull the year, month and day starting from the right. Not sure if the length of the day changes. Lets take the %date% variable and print it out That is when I realized you could use this to pull out parts of the current date (or time). What I didn’t know that was that you can use this character combination ‘:~’ to pull a substring out of an environment variable. The problem with that is the utility needs to be around if you want to send the batch file to someone. ![]() I found a way to take the %date% environment variable, and turn it into a valid string for a filename – without any extra programs or scripts.įor the longest time I used a little utility I created to do this. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |