map network

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hendrikbez
Posts: 20
Joined: 11 Sep 2008 22:36

map network

#1 Post by hendrikbez » 22 Mar 2012 03:50

I am trying to map network and copy files to D:\Backup\Sql_Backup, but I am getting only help

How can I sue this with spaces in my folders


net use R: \\000.00.0.00\Program Files\Microsoft SQL Server\MSSQL\BACKUP"
cd\
echo off
R:
cd \
Xcopy . /D /I /F /E /Y D:\Backup\Sql_Backup
net use R: /delete /y
exit

tonysathre
Posts: 14
Joined: 20 Mar 2012 10:07

Re: map network

#2 Post by tonysathre » 22 Mar 2012 05:04

You have to use double quotes around paths or file names with spaces.

@echo off
net use r: "\\000.00.0.00\Program Files\Microsoft SQL Server\MSSQL\BACKUP"
cd \
R:
Xcopy . /D /I /F /E /Y "D:\Backup\Sql_Backup"
net use r: /delete /y

Not sure why you were CDing to the root of the R: drive, there is no need to when changing drives as specifying only a drive letter will CD you to the root of that drive.

Tony

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: map network

#3 Post by foxidrive » 22 Mar 2012 07:56

tonysathre wrote:Not sure why you were CDing to the root of the R: drive, there is no need to when changing drives as specifying only a drive letter will CD you to the root of that drive.


Actually that's not true Tony, the working directory on a drive can be something other than the root and it will change to the working directory.

If it is the first time the drive is being accessed from a boot then the working directory is the root, and some file managers can be set to always start at the root folder.

Either of these should also work (untested) with the correct IP address in place:

Code: Select all

@echo off
net use r: "\\000.00.0.00\Program Files\Microsoft SQL Server\MSSQL\BACKUP"
pushd "r:\"
Xcopy . /D /I /F /E /Y "D:\Backup\Sql_Backup"
popd
net use r: /delete /y


Code: Select all

@echo off
net use r: "\\000.00.0.00\Program Files\Microsoft SQL Server\MSSQL\BACKUP"
Xcopy  /D /I /F /E /Y  "R:\*.*"  "D:\Backup\Sql_Backup"
net use r: /delete /y

tonysathre
Posts: 14
Joined: 20 Mar 2012 10:07

Re: map network

#4 Post by tonysathre » 22 Mar 2012 08:01

That's true, but considering he was mapping the drive, I assumed it would have been the first time the drive was accessed.

Tony

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: map network

#5 Post by foxidrive » 22 Mar 2012 08:12

tonysathre wrote:That's true, but considering he was mapping the drive, I assumed it would have been the first time the drive was accessed.


That's a fair comment - unless the drive was already mapped, I guess.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: map network

#6 Post by Squashman » 22 Mar 2012 16:08

I thought xcopy could use UNC paths so why bother doing the drive mapping?

But you could also use the pushd with the unc path and then use the xcopy command after that.

hendrikbez
Posts: 20
Joined: 11 Sep 2008 22:36

Re: map network

#7 Post by hendrikbez » 22 Mar 2012 22:58

Thanks to all of You, It is working.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: map network

#8 Post by foxidrive » 23 Mar 2012 00:46

Squashman wrote:I thought xcopy could use UNC paths so why bother doing the drive mapping?

But you could also use the pushd with the unc path and then use the xcopy command after that.


Thanks for that info. I'd never tried it so wasn't aware.


So both of these should work (with the correct IP address):

Code: Select all

@echo off
pushd "\\000.00.0.00\Program Files\Microsoft SQL Server\MSSQL\BACKUP"
Xcopy  /D /I /F /E /Y . "D:\Backup\Sql_Backup"
popd



Code: Select all

@echo off
xcopy /D /I /F /E /Y  "\\000.00.0.00\Program Files\Microsoft SQL Server\MSSQL\BACKUP\*.*"  "D:\Backup\Sql_Backup\"

Post Reply