Jump to content

Restore from RecycleBin if is not in Directory


Recommended Posts

Hi,

i m using this func: 

#Include <Array.au3>

Func _EnumRecycleBinItems($sRoot = '')

    Local $oShellApp, $oRecycleBin, $oFolderItems, $oItem

    $oShellApp = ObjCreate('Shell.Application')
    $oRecycleBin = $oShellApp.NameSpace(10)
    If Not IsObj($oRecycleBin) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $Ret, $Result[101][6] = [[0]]

    $sRoot = StringStripWS($sRoot, 3)
    If $sRoot > '' Then
        If StringInStr($sRoot, ':') Then
            $sRoot = StringRegExpReplace($sRoot, ':.*', '')
        Else
            $sRoot = ''
        EndIf
        If Not FileExists($sRoot & ':') Then
            Return SetError(1, 0, 0)
        EndIf
    EndIf
    $Ret = DllCall('shell32.dll', 'none', 'SHGetSettings', 'uint*', 0, 'dword', 2)
    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    $oFolderItems = $oRecycleBin.Items()
    For $oItem In $oFolderItems
        If ($sRoot > '') And ($sRoot <> StringLeft($oItem.Path, 1)) Then
            ContinueLoop
        EndIf
        $Result[0][0] += 1
        If $Result[0][0] > UBound($Result) - 1 Then
            ReDim $Result[$Result[0][0] + 100][UBound($Result, 2)]
        EndIf
        $Result[$Result[0][0]][0] = $oRecycleBin.GetDetailsOf($oItem, 0) ; Original name
        $Result[$Result[0][0]][1] = $oRecycleBin.GetDetailsOf($oItem, 1) ; Original path
        $Result[$Result[0][0]][2] = $oRecycleBin.GetDetailsOf($oItem, 2) ; Deleted date
;       $Result[$Result[0][0]][3] = $oRecycleBin.GetDetailsOf($oItem, 3) ; Size
        $Result[$Result[0][0]][3] = $oItem.Size ; Size
        $Result[$Result[0][0]][4] = FileGetAttrib($oItem.Path) ; Attributes
        $Result[$Result[0][0]][5] = $oItem.Path ; Recycle name
        If (Not $Ret[1]) And (Not StringInStr($Result[$Result[0][0]][4], 'D')) Then
            If StringInStr($Result[$Result[0][0]][5], '.') Then
                $Result[$Result[0][0]][0] &= StringRegExpReplace($Result[$Result[0][0]][5], '^.*\.', '.')
            EndIf
        EndIf
    Next
    ReDim $Result[$Result[0][0] + 1][UBound($Result, 2)]
    Return $Result
EndFunc   ;==>_EnumRecycleBinItems

$Data = _EnumRecycleBinItems()


; To recover a file all you need do is:
FileMove($Data[1][5], $Data[1][0]) ; Recovers the first file in the list

 

I would like to modify it so that if the file has not been deleted and therefore is not in the recycle bin, it start the rest of my program...

if instead there is a file in the recycle bin I would like it to restore it and then do the rest..is it possible? Cause now if there is not a file in recycle bin an error appears.

thx a lot


 
Link to comment
Share on other sites

Foud a way,if it can help someone.. tyvm!

 

If _elementExists($avArray, 11) Then
    _ArrayAdd($parArray, $avArray[11])
EndIf

Func _elementExists($array, $element)
    If $element > UBound($array)-1 Then Return False ; element is out of the array bounds
    Return True ; element is in array bounds
EndFunc
Edited by Zombie
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...