Solved

Robocopy not working with network files

Posted on 2006-11-26
12
615 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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