Page 1 of 1

Batch file to Copy Files from Local Drive to Share Drive

Posted: 28 Sep 2012 01:15
by raghuram.star
I want to run a Batch File to Copy Files from Local Drive to Share Drive,

Command I'm using is

Code: Select all

xcopy C:\Records\ \\Server Name\Directory Name\All Records\ /f /l /i /s /y /z


For some reason this is not working, CMD window is just blinking and closing

I am Generating this code through a VBA Macro from MS Excel

Macro Code is

Code: Select all

Sub CopyFiles()
    Dim fs As Scripting.FileSystemObject
    Dim file As TextStream
    Dim retVal
    Dim strFilePath, FSource, FDestination As String
   
    strFilePath = "C:\Test\"
    StrFile = "CopyFiles.bat"

    FSource = wksList.Range("D4").Value       '(this is C:\Records)
    FDestination = wksList.Range("D4").Value  '(this is \\Server Name\Directory Name\All Records)

    Set fs = New Scripting.FileSystemObject
    Set file = fs.CreateTextFile(strFilePath & StrFile)
    file.WriteLine ("xcopy " & FSource & "\*.* " & FDestination & "\ /i /e /y")
    file.Close
   
    retVal = Shell(strFilePath & StrFile)
End Sub


Is there any way to process this in DOS

Re: Batch file to Copy Files from Local Drive to Share Drive

Posted: 28 Sep 2012 01:18
by foxidrive
xcopy C:\Records\ \\Server Name\Directory Name\All Records\ /f /l /i /s /y /z


You have long filename elements and they need to be double quoted. Try this: but remove the /L to actually copy them.


Code: Select all

xcopy "C:\Records\*.*" "\\Server Name\Directory Name\All Records\" /f /l /i /s /y /z

Re: Batch file to Copy Files from Local Drive to Share Drive

Posted: 28 Sep 2012 03:19
by raghuram.star
@foxidrive :

Thanks for the reply, just got it with a click now... thanks

Re: Batch file to Copy Files from Local Drive to Share Drive

Posted: 30 Sep 2012 11:39
by moh_salah8
Hello,

you can use this, i use it to do this task.

Code: Select all

FOR /F %%G IN ('dir /b %1') DO ROBOCOPY %1\%%G\ *.* %2\%%G /z


Hope this will help u.

Thanks.