1753622 Members
5778 Online
108797 Solutions
New Discussion юеВ

Re: Append to a file

 
SOLVED
Go to solution
Kentucky
New Member

Append to a file

I would like to use the copy /xcopy or rename command and take a file and rename it to include the date - is that possible.
i.e. rename "file1" to "file1_mmddccyy". This will be automated. The goal is to send a file from local host to a remote host, Once ftp is complete. Then Rename the file on the local host with the date stamped at the end of the file.
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: Append to a file

(I assume your subject isn't accurate and you don't want to append?)
Are both hosts using Windows?
It should be possible to use rename.
Edgar Zapata
Esteemed Contributor
Solution

Re: Append to a file

Hi,

See if you can run this within a .cmd file:

SET fecha=%date:/=-%
copy file1 file1_%fecha%

You can either use copy or rename.

Kentucky
New Member

Re: Append to a file

Both host are using windows
WFHC-WI
Honored Contributor

Re: Append to a file

Edgar's method should work. As written however you would need to enclose the source and destination file names in quotes since the SET command here will return a value with a space.

Example "Thu 07-02-2009"

If you want to get rid of the day of the week, insert one more line between after the inital SET:

SET fecha=%fecha:~4%

This removes the first 4 characters of that variable. Good luck!
WFHC-WI
Honored Contributor

Re: Append to a file

One more thing... using UNC paths via the command line can sometimes lead to unexpected results. I recommend adding a command to map a drive before copying (and removing the mapping afterward if desired.)

NET USE Z: (share path)

...

NET USE Z: /delete
Kentucky
New Member

Re: Append to a file

Thanks Edgar and WFH-WI. It's working.