Batch file to Copy Files from Local Drive to Share Drive

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
raghuram.star
Posts: 3
Joined: 28 Sep 2012 01:08

Batch file to Copy Files from Local Drive to Share Drive

#1 Post by raghuram.star » 28 Sep 2012 01:15

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#2 Post by foxidrive » 28 Sep 2012 01:18

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

raghuram.star
Posts: 3
Joined: 28 Sep 2012 01:08

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

#3 Post by raghuram.star » 28 Sep 2012 03:19

@foxidrive :

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

moh_salah8
Posts: 14
Joined: 08 Aug 2012 09:24

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

#4 Post by moh_salah8 » 30 Sep 2012 11:39

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.

Post Reply