|
Answer» I did a quick search, didn't find what I needed, hope this isn't a duplicate...
I am looking to copy a file from "FileName" to " FileName" (replace with the actual FIPS date, e.g. 20060512, or any other date form that will work in the copy function). Is there any WAY to do this in DOS?
Thanks...That would depend on what version of "DOS" you have. This will work on some machines:
CODE: [Select]for /f "tokens=2-4 delims=/ " %%i in ('date /t') do ( copy filename.ext "%%k%%i%%j filename.ext" )
DOS is an operating system. It also comes in emulated versions under Windows. Please be specific so we can zero in on a solution that will work for you.
8-)Worked like a charm, right out of the box! Thanks a million!
My apologies on not telling you it's XP, but worked like a champ.
On a second note, is there a simple modification that would just toss in the time of day as well (say military time to make it easy)? This would be great for multiple copies of the same file each day...Sloppy, but it will work. If you want military time, I let you add the logic to add 12 hours if the meridian is PM
Code: [Select]@echo off for /f "tokens=2-4 delims=/ " %%i in ('date /t') do ( set yr=%%k set mn=%%i set da=%%j ) for /f "tokens=1-3 delims=: " %%x in ('time /t') do ( copy filename.ext "%yr%%mn%%da% %%x%%y%%z filename.ext" )
GOOD luck. 8-)Unfortunately, I'm stuck...
This worked to place the time on the file, but the %%z was null. %%y held both the minutes and the A/P. Say, for example, I removed the %%z altogether, it would still put the name of the file as (if the time it was copied was 12:28 PM) as 1228p.
If I were to just use the %%y (without the %%x), it would have it as simply 28p, with no way to separate out the p at the end. I am unaware of how to separate out the p on my own. Any clues? If you want to just tell me a place to go to find the answer, I'm more than happy to research it on my own...
Thanks!Another QUESTION would be:
is there Math functions in MSDOS, or will I have to create a list to use with logic?Best way to debug a FOR is inside out. I'm guessing the date part of this code works as advertised. TIME /T on my machine results in something like 04:51 PM Parsing this using : and space as a delimiter would result in three variables one holding 04, another holding 51 and the third holding PM. The example arbitrarily chose %%x as the first variable leaving %%y and %%z to hold the other pieces of data. End result should be %%x is 04, %%y is 51 and %%z is PM.
When the output file label is resolved the result should look like "20060513 0451PM filename.ext" without the quotes. This should have been your result.
To put the result in military time, you'd need to compare %%z with the literal PM and if equal, add 12 to %%x otherwise do nothing.
If you use SET with the /a switch you can do some simple math. Type set /? at any command prompt for details. Do not expect to find the value of pi.
Good luck. 8-)An alternative solution is to use the "system variables" %date% and %time% like this:
Code: [Select]for /f "tokens=2-8 delims=/:. " %%A in ("%date%:%time: =0%") do @set UNIQUE=%%C%%A%%B%%D%%E%%F%%G echo.Unique=%UNIQUE% echo.%date% %time% echo.%date% %time: =0%Which returns: Unique=2006010501060696 Thu 01/05/2006 1:06:06.96 Thu 01/05/2006 01:06:06.96
Ref:http://dostips.cmdtips.com/DtCodeSnippets.php#_Toc133425576 Hope this info is useful. Interestingly enough, I found where the discrepancy lies. If I type "time" and press enter, it gives me military time already, but prompts for a new time (e.g. 22:48:03.18). If I type "time /t" and press enter, it gives me a whole different time output (10:48p), but won't prompt me for a new time (which is absolutely invaluable in programming).
Not looking for an answer on this one...just giving more information.DosItHelp, that is an complete and total solution to the issue...thanks a million!
I can run the batch file multiple times, immediately one right after the other, and it will NEVER duplicate the same backup file. An absolutely genius solution...my overflowing gratitude for the flawless, above-and-beyond resolution.
|