Solved

Robocopy not working with network files

Posted on 2006-11-26
12
601 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
  • 6
  • 4
  • 2
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
Thanx Steve - I was headed off to bed when I posted it... ;^)
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
I'd just got up ...  
0
 

Author Comment

by:zubairvp123
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:zubairvp123
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
/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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

12 Experts available now in Live!

Get 1:1 Help Now