Soldato
Hi, I'm a noob to batch files and thought I'd learn by automating a task I have to do every month, but part of it is driving me mad and I'm sure there must be a simple way of doing it!
An export process copies a file to a location every month or so, each time a new export of the file is run it is saved to a new folder with the date on, the file name stays the same.
So the locations of the files would be something like:
G:\test\10-02-11\users.txt
G:\test\09-03-11\users.txt
G:\test\11-04-11\users.txt
I want to create a batch file that copies only the newest version of the users.txt file to another location, overwriting any existing file which is there.
I can't see how I can do it with copy or xcopy and get the newest version of only the file (no directories) unless I'm missing something, I thought about using dir and piping the result into copy but I can't get it to take only the first (newest) result after sorting (dir g:\test users.txt /a:-d /s /o:-d /b).
Points to note, I have no control of the export process and can't change that, also I can only run standard shell cmds, I don't have access to install other functions or use powershell / anything like that.
Like I said I am a noob at this and I'm using it as a chance to learn some basic scripting, but I'm a bit stuck. Any help or suggestions to point me in the right direction or some commands if something more complex is required would be much appreciated.
Cheers
An export process copies a file to a location every month or so, each time a new export of the file is run it is saved to a new folder with the date on, the file name stays the same.
So the locations of the files would be something like:
G:\test\10-02-11\users.txt
G:\test\09-03-11\users.txt
G:\test\11-04-11\users.txt
I want to create a batch file that copies only the newest version of the users.txt file to another location, overwriting any existing file which is there.
I can't see how I can do it with copy or xcopy and get the newest version of only the file (no directories) unless I'm missing something, I thought about using dir and piping the result into copy but I can't get it to take only the first (newest) result after sorting (dir g:\test users.txt /a:-d /s /o:-d /b).
Points to note, I have no control of the export process and can't change that, also I can only run standard shell cmds, I don't have access to install other functions or use powershell / anything like that.
Like I said I am a noob at this and I'm using it as a chance to learn some basic scripting, but I'm a bit stuck. Any help or suggestions to point me in the right direction or some commands if something more complex is required would be much appreciated.
Cheers