how do I copy a file as version?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
roger
Posts: 5
Joined: 24 Feb 2015 13:42

how do I copy a file as version?

#1 Post by roger » 24 Feb 2015 14:12

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

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how do I copy a file as version?

#2 Post by aGerman » 24 Feb 2015 18:20

The WMIC command provides a nice way to get a time stamp.

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

roger
Posts: 5
Joined: 24 Feb 2015 13:42

Re: how do I copy a file as version?

#3 Post by roger » 25 Feb 2015 02:33

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

roger
Posts: 5
Joined: 24 Feb 2015 13:42

Re: how do I copy a file as version?

#4 Post by roger » 25 Feb 2015 12:37

Yes, this does exacly what I meant, thanks a lot!
roger

Post Reply