Copy from network drive to local computer using batch

Posted on 2016-09-15
Last Modified: 2016-09-26
Hello experts,

Is there a batch file I can create which can copy all files from \\\Script\sw to C:\CSV\sw
I also need the same batch file to copy from \\\Script\hw to C:\CSV\hw

Is that possible?
Question by:Siddharth S
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 85

Expert Comment

ID: 41799831
@echo off
for %%a in (sw hw) do (
	robocopy.exe "\\\Script\%%a" "C:\CSV\%%a" /e /r:0 /w:0

Open in new window


Author Comment

by:Siddharth S
ID: 41799847
Wow, that was fast and works! Thanks but I have another thing. I have to copy from different locations onto one folder, can I incorporate it all in one.

Say I have to copy from  \\\Script\sw to  C:\CSV\sw and \\\Script\hw to C:\CSV\hw
LVL 85

Assisted Solution

oBdA earned 250 total points
ID: 41799873
Sorry, can't quite follow you.
The script above will copy two subfolders from a share into the respective subfolders locally.
Your second comment differs from the first only in the source IP address, if I'm not mistaken.
So do you want to collect the hw and sw folders from both servers into their local equivalents?
In other words:
\\\Script\hw  -\
                           >--> C:\CSV\hw
\\\Script\hw -/

\\\Script\sw  -\
                           >--> C:\CSV\sw
\\\Script\sw -/

Open in new window

If so, what's supposed to happen with duplicate file names?
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 56

Accepted Solution

Bill Prew earned 250 total points
ID: 41799894
Building on what oBdA proposed, and adding support for both multiple source servers, and multiple folders to copy, you could try the below.  The open question about duplicate handling still needs to be answered, but this should give you a starting point.

@echo off

set ServerList=\\ \\
set FolderList=sw hw
set DestFolder=C:\CSV

for %%a in (%ServerList%) do (
  for %%b in (%FolderList%) do (
    robocopy.exe "%%~a\Script\%%~b" "%DestFolder%\%%~b" /e /r:0 /w:0

Open in new window


Author Comment

by:Siddharth S
ID: 41800964
Thanks Bill, duplicate handling wont be a problem. If two files with the same name exists, then I want them to overwrite.
Let me try this and get back to you.
LVL 85

Expert Comment

ID: 41801038
You might want to add the /xo (eXclude Older) switch to the robocopy command then, to make sure only the latest file is copied.

Author Closing Comment

by:Siddharth S
ID: 41817226
Thanks guys, solved it. Great help as usual.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

617 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