Computing.Net > Forums > Programming > Copy and Rename Batch File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Copy and Rename Batch File

Reply to Message Icon

Name: scruff_neeps
Date: May 1, 2007 at 02:58:39 Pacific
OS: XP
CPU/Ram: PentiumD
Product: Dell
Comment:

Hi all,

I have been having problems writing a batch file to automate a process at work...

Basically we have provided a folder for users to paste Lotus Notes archive .nsf files into which will be copied into another secure folder on a server every second to form an archive. Naming conventions mean that every file should have a unique name but we all know thats not going to happen!

My aim is to construct a batch file that will copy the file to the folder on the server and rename the file from x.nsf to date+time_x.nsf

I can get the files to transfer between folders no problem but whatever i do i just can't get them to rename

This should at least give me a unique file name and a fighting chance of tracking down archives which users haven't named correctly.

I am in Europe but not fussed what format or order the date/time is in the file name. Anyone point me in the right direction?




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 1, 2007 at 04:36:59 Pacific
Reply:

You could generate random names.

copy d:\src\x.nsf s:\dest\%random%-x.nsf

with some error checking.

===================
To stamp with date/time, this bat will get YYYYMMDD via BIOS and is independent of region/langiafe etc.

http://golden-triangle.com/YMD8BAT.ZIP

To get the time into var, my time output is:

18:28:57.13

so I would:

::== mytime.bat
@echo off
setLocal EnableDelayedExpansion

set mytime=%time:~,2%%time:~3,2%%time:~6,2%%time:~9,2%
echo !mytime!
:==



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: scruff_neeps
Date: May 1, 2007 at 05:44:47 Pacific
Reply:

Cheers, I like the random names idea. I can always find the date/time by looking at the properties.

One last thing, when i use the random name generator for say bookmark.nsf it names the file 29171-rk.nsf. Is there a way to keep the file 29171-bookmark.nsf so if anybody follows the naming convention i will be able to quickly see who its is: 44561-SJones.nsf etc.

Here is how i have it coded:

xcopy c:\test1\*.nsf c:\test2\%random%-*.nsf

(If i just used the copy command it would only give me a 1Kb file the xcopy gives me the full thing)


0

Response Number 3
Name: Mechanix2Go
Date: May 2, 2007 at 00:54:19 Pacific
Reply:

"xcopy c:\test1\*.nsf c:\test2\%random%-*.nsf

(If i just used the copy command it would only give me a 1Kb file the xcopy gives me the full thing)"

There's something goofy going on. No reason for COPY to shorten a file. And when I do this:

C:\temp\d10\wipe\no2blank>xcopy *.bat x\%random%-*.bat
img.bat 20208-*.bat
Could not expand second file name so as to match first


=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Copy and Rename Batch File

Batch file copy and Rename www.computing.net/answers/programming/batch-file-copy-and-rename/18689.html

Copy and rename mmost recent file www.computing.net/answers/programming/copy-and-rename-mmost-recent-file/19636.html

Copy and rename same file 1000 times www.computing.net/answers/programming/copy-and-rename-same-file-1000-times/19839.html