Solved

Copy from network drive to local computer using batch

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

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

Is that possible?
0
Comment
Question by:Siddharth S
  • 3
  • 3
7 Comments
 
LVL 83

Expert Comment

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

Open in new window

1
 

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  \\192.168.0.99\Script\sw to  C:\CSV\sw and \\192.168.0.99\Script\hw to C:\CSV\hw
0
 
LVL 83

Assisted Solution

by:oBdA
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:
\\192.168.0.2\Script\hw  -\
                           >--> C:\CSV\hw
\\192.168.0.99\Script\hw -/

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

Open in new window

If so, what's supposed to happen with duplicate file names?
1
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 51

Accepted Solution

by:
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
setlocal

set ServerList=\\192.168.0.2 \\192.168.0.99
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

~bp
1
 

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.
0
 
LVL 83

Expert Comment

by:oBdA
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.
0
 

Author Closing Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now