Solved

Robocopy not working with network files

Posted on 2006-11-26
12
605 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating script that will zip file every 15 days 8 82
listing file names and path into notepad 3 61
Help with a batch file 13 81
Capture New Directory and set variable 21 68
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

18 Experts available now in Live!

Get 1:1 Help Now