Script Center > Gallery > Storage > Copy Files From the Recycle Bin
TechNet Script Center logo

Welcome to the TechNet Script Center Gallery!

Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.

Copy Files From the Recycle Bin

(Community)
Rate it:
 
 
 
 
 
Script Code
VBScript
'  Salvage copies of files with a specific extension from the recycle bin, 
'  even if they don't appear to be in the recycle bin because of a damaged INFO2 file.
'  Copied files will have format D<driveletter>N.<ext>
'  where driveletter is the drive the file was deleted on, N is an integer and ext is the file extension.
'  The file copies will go to a folder named BinSalvage on the drive this script is run from.
'  Steve Yandl


'  Establish the extension for the type files to be salvaged (copied) from the recycled or recycler folder.

strExt = "txt"


'  Get name of the drive this script is being run from

Set fso = CreateObject("Scripting.FileSystemObject")
strDrvName = fso.GetDriveName(Wscript.ScriptFullName)


'  Check if the drive is FAT32 or NTFS

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_LogicalDisk")
For Each objDisk in colDisks
   If objDisk.DeviceID = strDrvName Then
   strFileSys = objDisk.FileSystem
   End If
Next


'  Determine the Security Identifier string for the current user

Set objNetwork = CreateObject("WScript.Network")
strUser = objNetwork.UserName
strDomain = objNetwork.UserDomain

Set objAccount = objWMIService.Get _
    ("Win32_UserAccount.Name='" & strUser & "',Domain='" & strDomain & "'")
strSID = objAccount.SID


'  Find the path for the file folder holding files sent to the recycle bin on this drive

If strFileSys = "FAT32" Then
   strRecycleFldr = strDrvName & "\recycled"
Else
   strRecycleFldr = strDrvName & "\recycler\" & strSID
End If


'  Purge the folder to be receiving salvaged copies, create the folder if necessary

If Not fso.FolderExists(strDrvName & "\BinSalvage") Then
fso.CreateFolder(strDrvName & "\BinSalvage")
End If

fso.DeleteFile strDrvName & "\BinSalvage\*"


'  Copy files to be salvaged

fso.CopyFile strRecycleFldr & "\*." & strExt, strDrvName & "\BinSalvage\"
Platforms
Windows Server 2008 R2 No
Windows Server 2008 No
Windows Server 2003 No
Windows 7 No
Windows Vista No
Windows XP No
Windows 2000 No
For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.