Network Copy Batch file

G

Guest

I know exactly what I want to do from the old DOS days - trying to figure out
how to do it in Windows format.

Basically I want an icon on my desktop that will when clicked -
1 . erase a file from a specific location on my desktop
2. copy a file from a specified folder that is a mapped network drive (
p:\\server\plant)
3. paste it to a folder on my desktop (replacing the file erased in step 1)

Seems so simple, but I don't know how to do get the batch file to recognize
the network drive! I've tried messing around with the commands in CMD, and
can't seem to get it to recognize the file path to P:\. Keeps telling me
that the file isn't found. Can someone help me? THanks!
 
P

Pegasus \(MVP\)

Stoke said:
I know exactly what I want to do from the old DOS days - trying to figure out
how to do it in Windows format.

Basically I want an icon on my desktop that will when clicked -
1 . erase a file from a specific location on my desktop
2. copy a file from a specified folder that is a mapped network drive (
p:\\server\plant)
3. paste it to a folder on my desktop (replacing the file erased in step 1)

Seems so simple, but I don't know how to do get the batch file to recognize
the network drive! I've tried messing around with the commands in CMD, and
can't seem to get it to recognize the file path to P:\. Keeps telling me
that the file isn't found. Can someone help me? THanks!

The old DOS commands still work but they are considerably enhanced.
You can access your network drives as if they were local drives, e.g.

P:\plant\*.txt

or with a UNC name:

\\Server\ShareName\Plant\*.txt

If you show us your batch file line and quote the error message
you see then someone will tell you how to get it right.
 
G

Guest

THanks for helping me out.

The batch file reads:

del c:\plant\solid_4_0\default.dat
net use p:
copy p:\NetSetup_Solid_4_0\Registry settings\defaults.dat
c:\Plant\Solid_4_0\default.dat

When I run it, the CMD window pops up and disappears so quickly that I can't
read it.

the first line is working since the default.dat file is gone.

When I run CMD and type in the commands line by line, the first 2 lines
work, although net use p: gives me a summary of the
Local Name P:
Remote name \\server\plant
Resource type Disk
Status OK
# Opens 0
# Connections 1

and then goes back to the c:\Documents and Settings\cpc> prompt.

The copy command tells me "The system cannot find the file specified"

I've double / triple checked my spelling, underscores, etc.

Where's my error?
 
K

Kerry Brown

I'm assuming P: is already mapped. You need quotes around the path that has
the space in it.

del c:\plant\solid_4_0\default.dat
copy "p:\NetSetup_Solid_4_0\Registry settings\defaults.dat"
c:\Plant\Solid_4_0\default.dat

Instead of using a .bat file use a .cmd file. To test the file (.bat or
..cmd) open a cmd prompt and run the file from there. That way the window
will stay open after the file runs.
 
P

Pegasus \(MVP\)

Instead of using a .bat file use a .cmd file.

Under Win2000/XP, .bat and .cmd files behave in an
identical manner. There is no difference between the
two. Under Win9x, .cmd files will not run.

To test the file (.bat or
 
P

Pegasus \(MVP\)

Stoke said:
THanks for helping me out.

The batch file reads:

del c:\plant\solid_4_0\default.dat
net use p:
copy p:\NetSetup_Solid_4_0\Registry settings\defaults.dat
c:\Plant\Solid_4_0\default.dat

When I run it, the CMD window pops up and disappears so quickly that I can't
read it.

the first line is working since the default.dat file is gone.

When I run CMD and type in the commands line by line, the first 2 lines
work, although net use p: gives me a summary of the
Local Name P:
Remote name \\server\plant
Resource type Disk
Status OK
# Opens 0
# Connections 1

and then goes back to the c:\Documents and Settings\cpc> prompt.

The copy command tells me "The system cannot find the file specified"

I've double / triple checked my spelling, underscores, etc.

Where's my error?

Here is what you wrote:

del c:\plant\solid_4_0\default.dat
net use p:
copy p:\NetSetup_Solid_4_0\Registry settings\defaults.dat
c:\Plant\Solid_4_0\default.dat

and here is what you probably mean:

del c:\plant\solid_4_0\default.dat
net use p: \\YourServer\SomeShare
copy /y "p:\NetSetup_Solid_4_0\Registry settings\defaults.dat"
c:\Plant\Solid_4_0\default.dat

or perhaps:

del c:\plant\solid_4_0\default.dat
copy /y "\\YourServer\SomeShare\NetSetup_Solid_4_0\Registry
settings\defaults.dat" c:\Plant\Solid_4_0\default.dat

In other words, your batch file has three problems:
1. You never map a share to drive letter P:.
2. Your source file name has and embedded space and MUST
therefore be surrounded by double quotes.
3. You omitted the /y switch, which results in an irritating prompt
each time you run the batch file.

And as Kerry rightly said, always test your batch files from a Command
Prompt, never from the Run box.
 
K

Kerry Brown

Pegasus (MVP) said:
Under Win2000/XP, .bat and .cmd files behave in an
identical manner. There is no difference between the
two. Under Win9x, .cmd files will not run.


I don't have XP handy to test it but I thought that .bat would run
command.com whereas .cmd would run cmd.exe. I just tried it in Vista and it
works as you say. Both invoke cmd.exe. In any case I prefer to use .cmd when
using an NT based version of Windows. You may use some enhanced feature of a
command that doesn't work or may even cause a problem if the file is run in
Win9x.
 
P

Pegasus \(MVP\)

Kerry Brown said:
I don't have XP handy to test it but I thought that .bat would run
command.com whereas .cmd would run cmd.exe.

Here is a screenshot that tells it all:

c:\Temp>ver

Microsoft Windows XP [Version 5.1.2600]

c:\Temp>type test.bat
@echo off
echo %comspec%

c:\Temp>test.bat
C:\WINDOWS\system32\cmd.exe
 
G

Guest

Space ... needs quotes. Sometimes it is so obvious! THanks all for your
help in finding the obvious! It works like a charm!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top