Code for batch file (Windows XP)

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Code for batch file (Windows XP)

Post by Michael Abrams »

Is there a way to write a batch file to do the following: (pseudo code)

I want to “Copy” files from:

\\abc104fs\sc.it\Enrollment\Dummy Company\filename...

To :

\\servername\folder name\foldername2\foldername3

Thank you.

Michael

User avatar
HansV
Administrator
Posts: 78453
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code for batch file (Windows XP)

Post by HansV »

I have moved this thread from the Windows 7 forum to the Windows XP forum.

BATcher John Gray will no doubt provide a solution.
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Code for batch file (Windows XP)

Post by Michael Abrams »

Thanks Hans!

Michael

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Code for batch file (Windows XP)

Post by John Gray »

Many ways of doing this, provided you have the correct rights over the files on both servers and (quite probably) are running under an Administrator account! The simplest is probably the COPY command (note that the command line will probably wrap to the next line):

COPY /y "\\abc104fs\c$\sc.it\Enrollment\Dummy Company\filename1.ext" "\\servername\d$\folder name\foldername2\foldername3\"

COPY /y "\\abc104fs\c$\sc.it\Enrollment\Dummy Company\filename2.ext" "\\servername\d$\folder name\foldername2\foldername3\"

COPY /y "\\abc104fs\c$\sc.it\Enrollment\Dummy Company\filename3.ext" "\\servername\d$\folder name\foldername2\foldername3\"


It can be made easier if there is some pattern about the filenames, such as *.*, *.txt or fred*.*
If you give some example filenames it would help!
Please note that you need to reference sharenames on each server - I have used C$ and D$ respectively.
Similarly, if there exists one or more blanks in a file path, then the whole path has to be placed within double-quotes.
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Code for batch file (Windows XP)

Post by Michael Abrams »

Thank you John - I will have to work with over the weekend.

I am not sure what you mean reference the sharenames.

The path consists of the server name (abc104fs) and then the folder names.

What exactly is the c$ referring to?

Sorry if this is obvious, I am not too experienced (yet) with this type of request.

Thank you.

I will check in Monday with my result.

"It can be made easier if there is some pattern about the filenames, such as *.*, *.txt or fred*.*

All files are named sutter_somethingdifferent.dat

Michael

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Code for batch file (Windows XP)

Post by John Gray »

When you define a path to a folder on a server, you have to specify a share name.
The share name can be the administrative share, for example D$ for the D: drive,
or you can set up a share to point directly to a folder, such as myfoldersharename pointing to D:\somefolder\myfolder on the server.
So you could reference 'myfolder'
either as \\servername\myfoldersharename
or as \\servername\d$\somefolder\myfolder

Since your filenames have a unique pattern you could just use one of the above COPY commands

COPY /y "\\abc104fs\c$\sc.it\Enrollment\Dummy Company\sutter*.dat" "\\servername\d$\folder name\foldername2\foldername3\"

Here I am assuming the full paths to the source and target folders (which use the administrative shares corresponding to the drive letters on which they are located).

If you're not happy with what I've said above, let me have
SOURCE: server name, drive letter on which the folders are located, full path to folder (you've given me all this bar the drive letter)
TARGET: server name, drive letter on which the folders are located, full path to folder
and I should be able to work it out for you!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Code for batch file (Windows XP)

Post by Michael Abrams »

Does this work:
SOURCE:
\\scdc104fs\sc.it\Enrollment\Pacificare\
Where \\scdc104fs\sc.it\Enrollment\Pacificare is my “Z” drive

TARGET:
\\Scdc104fs\sc.Public\HMO Files
Where \\Scdc104fs\sc.Public\HMO Files is my “R” drive

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Code for batch file (Windows XP)

Post by John Gray »

Close!
I reckon the COPY command should therefore be:

copy /y "\\scdc104fs\z$\sc.it\Enrollment\Pacificare\sutter*.dat" "\\Scdc104fs\r$\sc.Public\HMO Files\"

While testing this, of course make sure that the target directory doesn't contain any files you want to keep.

Since the source and target folders are on the same server, are you actually running the BATch file containing the COPY command on this server? (If that's the case, we can simply significantly!)

LATER...

Just rereading your previous post, you say that
"\\scdc104fs\sc.it\Enrollment\Pacificare IS my “Z” drive"

If that's REALLY what you mean, you must have set up a mapping to that path, and so your copy command probably reduces to
copy /y "Z:\sutter*.dat" "R:\"
and you don't even need the double quotes!

Am I now completely confused?!
Last edited by John Gray on 05 Apr 2013, 19:17, edited 2 times in total.
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Code for batch file (Windows XP)

Post by Michael Abrams »

It's being run from:
\\scdc104fs\home (my H drive)

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Code for batch file (Windows XP)

Post by John Gray »

My "LATER" overlapped with your post.

If you are running the BATch file on the server on which both the source and target folders are located, then as far as I can judge all you need is
copy /y Z:\sutter*.dat R:\

I was initially assuming from what you said that you were copying from one server to another, and running the BATch copy on a third server (or PC). Hence the complication!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Code for batch file (Windows XP)

Post by Michael Abrams »

Wow - I will try this ASAP and get back to you.

I really appreciate your patience and help.

michael

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Code for batch file (Windows XP)

Post by John Gray »

Pas de problème!

BATch files can be extremely flexible but have to be precisely specified, otherwise 'unhappiness occurs'.

I hope your tests are successful!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Code for batch file (Windows XP)

Post by Michael Abrams »

This is just AWESOME !!

wow - WOW !!

Works PERFECTLY !!

Thank you SO much John - have a GREAT weekend !

Michael

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Code for batch file (Windows XP)

Post by John Gray »

Excellent. We are pleased.
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...