?
Solved

Robocopy not working with network files

Posted on 2006-11-26
12
Medium Priority
?
640 Views
Last Modified: 2012-06-27
Hi,
I'm new to robocopy. I've the below code for copying new files from one folder to the other. I've got this code from this same site and with the help of you all. However, when the source is in a network location, i.e not in my C:/ then it doesnt work. Can you please help with what could be the possible reason?

@echo off
set source1=I:\DTF\00 DTF Daily Report Drop Box\Daily Activity Report
set source2=C:\Source
set dest=C:\dest1
set n=7
cd "%source1%"
for /r %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /M /

cd "%source2%"
for /r %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /M >>log.txt

Sirbounty, It takes the files from source2 but not source1.
Also it would be great if you could show me how to have log.txt files that get generated showing which all files were successfully copied and which files were skipped.
0
Comment
Question by:zubairvp123
[X]
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
  • 6
  • 4
  • 2
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18017154
Try this: (you can remove the :: comments if they get in the way)

@echo off
::set source1 to equal the LFN enclosed in quotes
set source1="I:\DTF\00 DTF Daily Report Drop Box\Daily Activity Report"
set source2=C:\Source
set dest=C:\dest1
::set variable for log file output
set log=C:\Log.txt
set n=7
::loop through both sources since the command string is the same
for %%x in (%source1% %source2%) do (
  for /r %%x %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /M /Log+:%log%
  )
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18017437
I tend to add the /tee and /np options to the end of the robocopy commandline too - that shows the progress on the screen at the same time as the log file so you can see what is going on.... if it is scheduled job that may be pointless of course...

I think you'll find the above fixes your issue though, to explain, probably nothing to do with the network location as such, just the fact that you had spaces in that path and not the other - you then need quotes around the name...

Steve
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18018973
Thanx Steve - I was headed off to bed when I posted it... ;^)
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 18019025
I'd just got up ...  
0
 

Author Comment

by:zubairvp123
ID: 18025350
Hi Thanks for your response.
I had and I have again tried putting the double quotes in the source aswell as around the variable( "%source%"). I've tried all the combinations but doesnt seem to work. please find below the log file generated if we can figure out something from it. What I feel is if it's a network file then the source by default becomes my desktop. if it's in the C then it works fantastically fine.

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Tue Nov 28 07:22:57 2006

   Source : C:\DOCUME~1\hphaneef\Desktop\
     Dest : C:\dest1\

    Files : *DDR*.xls
          
  Options : /COPY:DAT /MAXAGE:7 /R:1000000 /W:30

------------------------------------------------------------------------------

                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :         2         0         2         0         0        12
    Bytes :    23.0 k         0    23.0 k         0         0   469.0 k
    Times :   0:00:00   0:00:00                       0:00:00   0:00:00

    Ended : Tue Nov 28 07:22:59 2006
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18025388
That doesn't tell us anything, cause each source is identifying a source on your local drive.
Robocopy won't care if it's a network drive.  

Are you sure it's mapped?
You could also try with the UNC
\\servername\share\folder
instead of I:\folder
0
 

Author Comment

by:zubairvp123
ID: 18025423
still doesnt work. Ofcource I'm mapped to the network. I'm only working on network files. I cant afford to change the path either. is it because the no. of characters in the source string exceeded? i thought it could take upto 255 characters but this is only 135 i guess. please find below my code. i'm sure i'm missing out something.

set source="\\mannai\DTF\07 DTF Well FIles\7.04 AKG\01 Active\01.2 Block-A\01 WHP4 - AKG1\10- Daily Reports (DDR-DCR etc)\01 Daily Activity Reports"
set source1=C:\Source
set dest=C:\dest1
set log=C:\dest1\Log.txt
set n=7

cd %source%
for /r %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /Log+:%log%

cd "%source1%"
for /r %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /Log+:%log%
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 1000 total points
ID: 18025456
for starters,
put your source in the for-loop

for /r %source% %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /Log+:%log%

for /r %source1% %%a in (*DDR*.xls) do robocopy %%~dpsa %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /Log+:%log%

if that doesn't change anything, let's try breaking it apart...

place the following in a test batch file:

setlocal
set log=c:\dest1\log.txt
set n=7
for /r %source% %%a in (*DDR*.xls) do call :process "%%~dpa"
goto :eof

:process
set srcPath=%1
robocopy %srcPath% %dest% *DDR*.xls /copy:DAT /MAXAGE:%n% /Log+:%log%

::post the results...
0
 

Author Comment

by:zubairvp123
ID: 18025514
WOW!!! The code for starters worked absoulutely fine. Thanks. I didnt have to do the test batch file. But let me do a bit of testing before I actually close out this question.
Thanks again!!!
0
 

Author Comment

by:zubairvp123
ID: 18035304
Hi should I be using the /m to copy only newer and modified files? to set the attributes off after copying?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18036734
/m checks the archive bit.
If you're not familiar with how that works...'something' has to remove the bit.  Typically this is backup software that would do that.  However, you can 'force' removal by typing attrib -a filename.ext
So, unless you're using backup software or are going to implement your own manual removal, I don't see the benefit for you.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18036745
To add to that - /m also resets the bit, so if you want to keep track of files copied using that method, then it may make sense.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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