Valnurat Posted December 15, 2016 Posted December 15, 2016 I have a task that I need to clear terminated users home directory in the company. If the path to the folder have more than 256 characters I use robocopy to delete the folder. My function is this: Func _RoboCopy_NoAD_Accounts($sFolderToDel) $prog = @SystemDir & '\RoboCopy.exe' $options = '/s /mir' $logg = '/LOG+:LogPath' Local $sStr = StringReverse($sFolderToDel) $sStr = StringReverse(StringMid($sStr,StringInStr($sStr,'\'),StringLen($sStr))) if DirCreate($sStr & 'empty_dir') <> 0 Then Local $source = $sStr & 'empty_dir' $sComputername & '.log /NFL /NDL') Return RunWait('"' & $prog & '" "' & $source & '" "' & $sFolderToDel & '" ' & $options, "", @SW_MAXIMIZE) ; & ' ' & $logg & $sComputername & '.log /NFL /NDL') DirRemove($source) DirRemove($sFolderToDel) EndIf EndFunc ;==>_RoboCopy_NoAD_Accounts and I call it like this: if DirRemove($aListOfAllHomeFolders[$iIndex][0] & "\" & $aListOfAllhomeFolders[$iIndex][1], 1) <> 1 Then If _RoboCopy_NoAD_Accounts($aListOfAllHomeFolders[$iIndex][0] & "\" & $aListOfAllhomeFolders[$iIndex][1]) <> 2 Then _FileWriteLog($hFile, 'Robo Failed to delete ' & $aListOfAllHomeFolders[$iIndex][0] & "\" & $aListOfAllhomeFolders[$iIndex][1]) Else _FileWriteLog($hFile, 'Robo Succeed to delete ' & $aListOfAllHomeFolders[$iIndex][0] & "\" & $aListOfAllhomeFolders[$iIndex][1]) $iTotalSize = $iTotalSize + $iSize EndIf Else _FileWriteLog($hFile, 'Succeed to delete ' & $aListOfAllHomeFolders[$iIndex][0] & "\" & $aListOfAllhomeFolders[$iIndex][1]) $iTotalSize = $iTotalSize + $iSize EndIf But if the call to RoboCopy function and it is meet with a Error 5 (Access denied) is does not return it just continue to try to delete. Yours sincerely Kenneth.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now