Italiano

Restore files from recycle bin

9 posts in this topic

Hello...

 

as title says... is there a method that I can use in Autoit to restore single files from recycle bin? If I am right, there is just a command to empty it (filerecycleempty). Since  I was planning to add a simple "undo" in a script that i am writing to restore files that the script deletes, i was wondering if i could restore them directly with autoit.

Any ideas?

Sorry for my bad english and sorry if it exists already a function for it  and i was not good to find it :)

thx

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Italiano,

I use this code from Yashied to enumerate the contents of the Recycle bin. Once you have the list,  you can use FileMove to move the file as shown:

#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()
_ArrayDisplay($Data)

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

M23

Edited by Melba23
Fixed text formatting
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Very much appreciated, thank you a lot! I will play with your code :)

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Quote

I use this code from Yashied to restore the contents of the Recycle bin. Once you have the list,  you can use FileMove to move the file as shown:

Does this script works on Windows 10?

Edited by stasia8954

Share this post


Link to post
Share on other sites

@stasia8954, it would probably have taken you less time to actually try it than it did to write your post. Have you tried it for yourself? Are you experiencing issues? If so, instead of just a blanket "is this supposed to work" question, try explaining in detail what problems you're running into.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

On 2016/3/26 at 11:18 PM, Melba23 said:

Italian,

I use this code from Yashied to enumerate the contents of the Recycle bin. Once you have the list,  you can read : https://www.tunesbro.com/recover-deleted-contats-from-iphone-without-backup.html

I want to know , if there is a time limit ,i accidentally lost data last month , up to now , those data have not been recovered back , i am not sure whether your method will help me recover back them , 

Edited by Yanccery

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi.

This script shows only the files which are currently in the recycle bin. They can lay there for years if you don't empty your recycle bin. If you look manually into your recycle bin and the file is in there the script will work.

But I guess you have emptied your recycle bin and now looking for a solution to restore your burned files? This script isn't about that.

Regards, Conrad

Edited by Simpel
Typo

SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

On 2017/8/9 at 4:27 PM, Yanccery said:

I want to know , if there is a time limit ,i accidentally lost data last month , up to now , those data have not been recovered back , i am not sure whether your method will help me recover back them , 

Must have been overwritten by new data,  if you lost data, you can only get them back with a recovery tool as soon as possible.

Edited by Shehab0

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

On 2017/8/9 at 4:27 PM, Yanccery said:

I want to know , if there is a time limit ,i accidentally lost data last month , up to now , those data have not been recovered back , i am not sure whether your method will help me recover back them , 

http://www.mobiledic.com/android-data-rescuer.html

 

On 2017/9/26 at 4:11 PM, Shehab0 said:

Must have been overwritten by new data,  if you lost data, you can only get them back with a recovery tool as soon as possible.

It hard to say , there are no chance ,once the data is overwritten ,they are completely erased from memory card or other device , 

Edited by Naklsder

Share this post


Link to post
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