#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <File.au3>
$hGUI = GUICreate('Demo File Restore',1110,600)
GUISetBkColor(0xB1B1B1)
$hLabelRecyCler=GUICtrlCreateLabel('Папка корзины',5,5,100,20)
$sStyle=BitOR($LVS_REPORT,$LVS_ShowSELALWAYS)
$sExStyle=BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)
$hListViewRecycler = GUICtrlCreateListView("", 5, 30, 800,520,$sStyle,$sExStyle)
GUICtrlSetBkColor(-1,0xDBDB00)
_GUICtrlListView_InsertColumn ($hListViewRecycler, 0, 'Original name', 160)
_GUICtrlListView_InsertColumn ($hListViewRecycler, 1, 'Original Patch', 300)
_GUICtrlListView_InsertColumn ($hListViewRecycler, 2, 'Deleted Data', 100)
_GUICtrlListView_InsertColumn ($hListViewRecycler, 3, 'Size', 50)
_GUICtrlListView_InsertColumn ($hListViewRecycler, 4, 'Atributes', 40)
_GUICtrlListView_InsertColumn ($hListViewRecycler, 5, 'Recycle name', 300)
$hLabelTempFolder=GUICtrlCreateLabel('Папка : Temp Folder' ,810,5,300,20)
$hListView = GUICtrlCreateListView("", 810, 30, 300,520,$sStyle,$sExStyle)
GUICtrlSetBkColor(-1,0xDBDBDB)
_GUICtrlListView_InsertColumn ($hListView, 0, 'FileName', 160)
_GUICtrlListView_InsertColumn ($hListView, 1, 'FileFullName', 700)
$hBtRestore = GUICtrlCreateButton ("Restore",10,570,70,20)
$hBtClearRecycler = GUICtrlCreateButton ("Clear Recycler",90,570,110,20)
$hBtTestFileCreate=GUICtrlCreateButton ("TestFile Create",610,-1,100,'')
$hBtDelete = GUICtrlCreateButton ("Delete",850,-1,70,'')
$hBtBack = GUICtrlCreateButton ("Back",1030,-1,'','')
GUISetState()
; Создаем в рабочей папке скрипта Папку : " Temp Folder "
DirCreate(@ScriptDir & '\Temp Folder')
Update_RecyclerFolderLV($hListViewRecycler)
Update_TempFolderLV($hListView)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
FileDelete(@ScriptDir & '\Temp Folder')
Exit
Case $hBtClearRecycler
FileRecycleEmpty()
Case $hBtTestFileCreate
; Создаем в папке : "Temp Folder " файлы\папки для тестирования
For $i=1 To 3
DirCreate(@ScriptDir & '\Temp Folder\TestFolder ' & $i)
_FileCreate(@ScriptDir & '\Temp Folder\TestFile ' & $i & '.txt')
Next
Case $hBtDelete
$hItem=_GUICtrlListView_GetSelectedIndices($hListView)
If $hItem='' Then ContinueLoop
$hFile=_GUICtrlListView_GetItemText( GUICtrlGetHandle($hListView),$hItem,1)
FileRecycle($hFile)
Case $hBtBack
FileRestore($hFile)
Case $hBtRestore
$hItemRec=_GUICtrlListView_GetSelectedIndices($hListViewRecycler)
If $hItemRec='' Then ContinueLoop
$hFileRec=_GUICtrlListView_GetItemText( GUICtrlGetHandle($hListViewRecycler),$hItemRec,5)
FileRestore($hFileRec,1)
Case else
ContinueLoop
EndSwitch
Update_RecyclerFolderLV($hListViewRecycler)
Update_TempFolderLV($hListView)
WEnd
Func Update_RecyclerFolderLV($hLV)
$aData=_EnumRecycleBinItems()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hLV))
For $i=1 To UBound($aData,1)-1
_GUICtrlListView_AddItem($hLV, $aData[$i][0])
For $j=1 To UBound($aData,2)-1
_GUICtrlListView_AddSubItem($hLV, $i-1,$aData[$i][$j],$j)
Next
Next
EndFunc
Func Update_TempFolderLV($hLV)
$aArray=_FileListToArray( @ScriptDir & '\Temp Folder','*.*',0)
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hLV))
For $i=1 To UBound($aArray,1)-1
_GUICtrlListView_AddItem($hLV,$aArray[$i])
_GUICtrlListView_AddSubItem($hLV, $i-1,@ScriptDir & '\Temp Folder\' & $aArray[$i],1)
Next
EndFunc
Func FileRestore($sFile,$iFlag=0)
$aData=_EnumRecycleBinItems()
For $i=1 To UBound ($aData,1)-1
$sOriginalFullName=$aData[$i][1] & '\' & $aData[$i][0]
$sRecyclerFullName=$aData[$i][5]
$sAtributes=$aData[$i][4]
$sCompare = $sOriginalFullName
If $iFlag <> 0 Then $sCompare = $sRecyclerFullName
If $sCompare=$sFile Then
If $sAtributes='D' Then
DirMove($sRecyclerFullName , $sOriginalFullName)
Else
FileMove($sRecyclerFullName , $sOriginalFullName)
EndIf
ExitLoop
EndIf
Next
EndFunc
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