Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch file help - need to generate new unique filename

Status
Not open for further replies.

mucous

Technical User
Nov 28, 2002
164
US
Hi,

I started a small project (my first) using a batch file to grab a file then send it via FTP to another server. It's working well but now I need that file to automatically be renamed each time it's generated. I'm very new to batch files/scripts and could use some help if possible.

Here are my details...

The file is generated by an app. It spits it out with the same filename each time. My batch file so far, copies it into a folder I've named FTP. Once it's there, it gets sent via FTP to another server. Somewhere in this batch file, I would like the target file to be uniquely renamed, ie: it's called xyz.txt now. Since it's sent via the FTP transfer many times though the day, it needs to be unique so the receiving server does not overwrite it each time it comes across the pipe. I was thinking maybe adding the date and or time would do the trick, but would be happy if the file simply had a number added to it like xyz1, xyz2, xyz3.txt and so on. If anyone out there is familiar with how I can accomplish this, you'd make my day! I apologize if this post should be in another forum.

Thanks for your help!
 
For the date and time, you can rename the files to the current date or time. I did the test with the date because it requires some changes in the regional setting.

You can add a command like:

ren xyx.txt "%DATE%.TXT"
copy "%DATE%.TXT" T:\Backup

(or you can simply copy the file directly to T:\BACKUP)

That will create a file called: "11.18.2003.TXT" . The trick is to change your date seperator in your regional settings from "/" to "." . You cannot create the file to 11/18/2003.txt cause it does not accept the slashes.



"In space, nobody can hear you click..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top