• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

Robocopy not working with network files

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
zubairvp123
Asked:
zubairvp123
  • 6
  • 4
  • 2
1 Solution
 
sirbountyCommented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
sirbountyCommented:
Thanx Steve - I was headed off to bed when I posted it... ;^)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Steve KnightIT ConsultancyCommented:
I'd just got up ...  
0
 
zubairvp123Author Commented:
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
 
sirbountyCommented:
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
 
zubairvp123Author Commented:
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
 
sirbountyCommented:
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
 
zubairvp123Author Commented:
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
 
zubairvp123Author Commented:
Hi should I be using the /m to copy only newer and modified files? to set the attributes off after copying?
0
 
sirbountyCommented:
/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
 
sirbountyCommented:
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

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now