Jump to content

_CopyRobo() Folder And File Copy With Robocopy


Chimaera
 Share

Recommended Posts

Ive used Robocopy for a number of years and its a bit of a devil to get working, especially if your not familiar with it.

I came across a debate on here about copying folders and adapted the example to work with Robocopy

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

        ; Needs Robocopy Version XP_026 or XP_027 for $sCopyParams Compatibility (C:\windows\system32\)
        ;XP_027 installed in Vista or greater ( Not for XP )

Local Const $sSource = @UserProfileDir & '\Desktop'
Local Const $sDestination = 'D:\Backup\Desktop'
Local Const $sSearchParams = '*.*' ; _Change_String('*.jpg|*.png') for multiple selections
Local Const $sCopyParams = '/COPY:D /S /ZB /XJD /XJF /R:0 /W:0 /XA:SHT /NJS'
        ; /COPY:D = Copy Data /S = Copy Subfolders /ZB = Use Restartable Mode /XJD = Exclude junction Points For Directorys /XJF = Exclude junction Points For Files
        ; /R:0 = Retry Time - 0 /W:0 = Wait Time - 0 /XA:SHT = No System / Hidden or Temp Files Backed Up /NJS = No Job Summary in the CMD window
Local Const $sExcludeFiles = '/XF ' & _Change_String('add.ini|your.ini|files.ini|to.ini|exclude.ini|here.ini') ; e.g. '*.iss|*.lnk|*.properties|*.session|aaw7boot.log|Amanda.wma'
Local Const $sExcludeFolders = '/XD ' & '"' & $sDestination & '"' & ' ' & _Change_String('Add|your|folders|to|exclude|here') ; e.g. 'ATI|AMD|Intel|Program Files|Program Files (x86)|Windows'


_CopyRobo($sSource, $sDestination, $sSearchParams, $sCopyParams, $sExcludeFiles, $sExcludeFolders)


Func _CopyRobo($sSourceFolder, $sDestFolder, $sSearchParams, $sCopyParams, $sExcludeFiles, $sExcludeFolders)
    DirRemove($sDestFolder, 1)
    Local Const $iSourceSize = DirGetSize($sSourceFolder)
    Local Const $iRoboPID = Run('robocopy.exe' & ' ' & '"' & $sSourceFolder & '"' & ' ' & '"' & $sDestFolder & '"' & ' ' & $sSearchParams & ' ' & $sCopyParams & ' ' & $sExcludeFiles & ' ' & $sExcludeFolders, '', @SW_SHOW); @SW_HIDE Once its working
    Local $iPercent = 0
    ProgressOn('Copy Progress', 'Please Wait...')
    Do
        $iPercent = Int((DirGetSize($sDestFolder) / $iSourceSize) * 100)
        ProgressSet($iPercent, $iPercent & ' percent complete')
        Sleep(20)
    Until Not ProcessExists($iRoboPID)
    ProgressOff()
EndFunc   ;==>_CopyRobo

Func _Change_String($sString)
    Return '"' & StringReplace($sString, "|", '" "') & '"'
EndFunc   ;==>_Change_String

;~ ConsoleWrite("Search Files Params = " & $sSearchParams & @CRLF) ; For double cheking
;~ ConsoleWrite("Exclude FileList Params = " & $sExcludeFiles & @CRLF) ; For double cheking
;~ ConsoleWrite("Exclude FolderList Params = " & $sExcludeFolders & @CRLF) ; For double cheking

Based loosely on this

Hope it helps :)

Thx to guinness and Melba for the assist

Edited by Chimaera
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...