Solved

batch file to copy remotly a file

Posted on 2007-11-28
6
673 Views
Last Modified: 2008-02-01
i want to replace a file  (Connect.ini) that is stored on C:\Program Files\SIMS\SIMS .net  (note that SIMS .net  is a folder) in a remote computer. The new file ( the one i want to replcalce the existing one with) is stored on the root of my C: (where the script will run from). Here is what i tried:

Please note that %1 is the remote computer name
ATTEMPT 1
copy /y c:\Connect.ini  \\%1\C$\Program Files\SIMS\SIMS .net\

I get the following error message for this one:
'The syntax of the command is incorrect.'


ATTEMPT 2
rem net use z: \\%1\c$
rem del z:\Program Files\SIMS\SIMS .net\Connect.ini
rem copy c:\Connect.ini z:\Program Files\SIMS\SIMS .net\Connect.ini
rem net use z: /d

I get the following error message for this one:

C:\>net use z: /d
z: was deleted successfully.

C:\>net use z: \\A61-01\c$
The command completed successfully.

C:\>del z:\Program Files\SIMS\SIMS .net\Connect.ini
The system cannot find the path specified.

C:\>copy c:\Connect.ini z:\Program Files\SIMS\SIMS .net\Connect.ini
The syntax of the command is incorrect.

C:\>net use z: /d
There are open files and/or incomplete directory searches pending on the connection to z:.
Is it OK to continue disconnecting and force them closed? (Y/N) [N]:

 Can anyone help please?
0
Comment
Question by:olchs
  • 4
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 20365050
copy /y c:\Connect.ini  "\\%~1\C$\Program Files\SIMS\SIMS .net\"
0
 
LVL 2

Expert Comment

by:pinkisthenewblue
ID: 20365070
Firstly, good practice to put all paths in quotations. I can see that you haven't - so it will treat copy /y c:\Connect.ini  \\%1\C$\Program Files\SIMS\SIMS .net\ as:

 copy  file c:\connect.ini to \\%1\c$\Program with parameters  Files\SIMS\SIMS, .net\ and /y
Same with the net use.

Secondly, If run from a batch file you need two percent signs.

copy /y "c:\Connect.ini"  "\\%%1\C$\Program Files\SIMS\SIMS .net\"

Hope that works for you.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 20365076
Spaces act as separators on the command line.

program this is parameter number 5

But

program "this is parameter number 1"


Double quotes are used to embed spaces in parameters.

The same applies to program names.

C:\Program <<< program
Files\SIMS\SIMS <<< parameter 1
.NET\ <<<< parameter 2

rather than "C:\Program Files\SIMS\SIMS .NET\"

The %1 is not quite OK either.

Follow this ...

@ECHO OFF
ECHO 1 = %1
ECHO 2 = %2

Save that as test.bat and run it ...

test C:\Program Files

and then

test "C:\Program Files"

See the difference?

See the problem?

No?

OK. The problem is that I just said you need to use quotes to add spaces.

So, "%1" wraps the first parameter in quotes.

BUT you already wrapped it in quotes to get the space in to start with, so you end up with ...

""C:\Program Files""

The ~ in %~1 removes the quotes, leaving you with ...

"C:\Program Files"

You normally use ~ to strip the quotes from any parameter coming into the script and apply your own as needed.

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 20365080
pinkisthenewblue,

You do ___NOT___ need 2 % for command line parameters.

You ONLY need 2 % when dealing with FOR variables.

e.g.

At the command line ...

FOR %A IN (a b c) DO ECHO %A

But in a bat file ...

FOR %%A IN (a b c) DO ECHO %%A


0
 
LVL 2

Expert Comment

by:pinkisthenewblue
ID: 20365104
Yeah I figured he was, I've never seen anyone use variables like that thats not in a for statement. But if not then take head olchs.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 20365167
If you think that is bad, try decoding this ...

Pretty obvious when you understand the syntax, but even so, a nightmare for a beginner.
@ECHO OFF
SET UnivDateTokens=1-3 
FOR /F "tokens=1 delims=.:/-, " %%O IN ('DATE /T') DO SET UnivDatePart1=%%O
IF "%UnivDatePart1:~0,1%" GTR "9" SET UnivDateTokens=2-4 
FOR /F "tokens=%UnivDateTokens% delims=.:/-, " %%P in ('DATE /T') DO ( 
	FOR /F "skip=1 tokens=2-4 delims=/-,()." %%S IN ('ECHO.^|DATE') DO ( 
		SET %%S=%%P
		SET %%T=%%Q
		SET %%U=%%R
		SET UnivDatePart1=
		SET UnivDateTokens=
		)
	)

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Nmap how to find wich type of socks is this? 4 97
how to execute all sub dir 2 41
Batch File tool box 5 50
WMIC Command LIne 5 27
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question