Hi DOStips forum members.
I have a question on whick the answer will be not that difficult for an experienced batch file user, but likely I'm not experienced enough.
My question: I have a file that I want tcopy to a new location giving the file a 'version' like for instance a date tag.
example:
I have a file c:\FILE.txt
At every boot of my PC (or via Windows scheduler) I want to copy this file giving it a unique name, and by that having this file 100 times after 100 reboots. By this I will have the complete history of the file.
A following number would be fine (resulting in file FILE_1.txt, FILE_2.txt, FILE_3.txt etc), dut a date tag would be nicer (FILE_01-01-2015.txt , FILE_02-01-2015, FILE_03-01-205, etc)
Also creating a new directory for each time the file is copied is fine (C:\01-01-215\FILE.txt , c:\02-01-2015\FILE.txt, etc) as long as I have a copy every time , instead of overwriting the old copy.
Somehow the date needs to be converted to text, that needs to be appended to the original filename (or be name of a new subdirectory)
I know the original filename (it's always the same file, like in this example FILE.txt, so I don't need to use wildcards), so it's equal to me to use copy or xcopy.
I think my question is not so difficult for an experienced DOS command user, so I would be happy if you could privide me the command lines to get a batch file that fullfils my wishes.
Many thanks in advance.
Roger
how do I copy a file as version?
Moderator: DosItHelp
Re: how do I copy a file as version?
The WMIC command provides a nice way to get a time stamp.
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "skip=1 delims=." %%d in ('WMIC OS Get LocalDateTime^|findstr .') do set "timestamp=%%d"
copy "C:\FILE.txt" "C:\FILE_%timestamp%.txt"
Regards
aGerman
Re: how do I copy a file as version?
Wow that's a fast reply.
Too difficult for me to figure out myself.
I'll check later today if it does what it should (but do't realy doubt).
THANKS! Roger
Too difficult for me to figure out myself.
I'll check later today if it does what it should (but do't realy doubt).
THANKS! Roger
Re: how do I copy a file as version?
Yes, this does exacly what I meant, thanks a lot!
roger
roger