列出回收站中的文件

发布于 2024-07-16 12:57:09 字数 898 浏览 7 评论 0原文

我想从命令行列出 Vista 中回收站中的文件。 到目前为止我有这个:

dir C:\$Recycle.Bin /s /b >> recyclebin.txt

这工作正常,我得到的输出是这样的:

C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$I2H8K48.zip C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$IE94UAG.exe C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$IR4P99W.rar C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$R2H8K48.zip C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$RE94UAG.exe C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$RR4P99W.rar

我的回收站中只有 3 个名为 auto 的文件-it-v3-setup.exefcleanerportable.rarReinstall.rar

有什么方法可以将这些名称放入 .txt 文件列表中,而不是上面那些代码命名的文件吗?

I want to list the files that are in the recycle bin in Vista from the command line. So far I have this:

dir C:\$Recycle.Bin /s /b >> recyclebin.txt

This works alright, the output I get is this:

C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$I2H8K48.zip
C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$IE94UAG.exe
C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$IR4P99W.rar
C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$R2H8K48.zip
C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$RE94UAG.exe
C:\$Recycle.bin\S-1-5-21-931442927-344369455-2477061601-1000\$RR4P99W.rar

And I only have 3 files in my recycle bin named auto-it-v3-setup.exe, fcleanerportable.rar and Reinstall.rar.

Is there any way to get these names into a .txt file list, rather than those code-named files above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期情话 2024-07-23 12:57:09

要使用 PowerShell 按原始位置列出回收站中的文件(另存为 file.ps1,删除 | 之前的换行符,以便只得到两行):

(New-Object -ComObject Shell.Application).NameSpace(0x0a).Items()
|select @{n="OriginalLocation";e={$_.ExtendedProperty("{9B174B33-40FF-11D2-A27E-00C04FC30871} 2")}},Name
| export-csv -delimiter "\" -path C:\Users\UserName\Desktop\recycleBinFiles.txt -NoTypeInformation

(gc C:\Users\UserName\Desktop\recycleBinFiles.txt | select -Skip 1)
| % {$_.Replace('"','')}
| set-content C:\Users\UserName\Desktop\recycleBinFiles.txt

To list files in Recycle Bin by their original location using PowerShell (save as file.ps1, remove line breaks before | so that you get only two lines):

(New-Object -ComObject Shell.Application).NameSpace(0x0a).Items()
|select @{n="OriginalLocation";e={$_.ExtendedProperty("{9B174B33-40FF-11D2-A27E-00C04FC30871} 2")}},Name
| export-csv -delimiter "\" -path C:\Users\UserName\Desktop\recycleBinFiles.txt -NoTypeInformation

(gc C:\Users\UserName\Desktop\recycleBinFiles.txt | select -Skip 1)
| % {$_.Replace('"','')}
| set-content C:\Users\UserName\Desktop\recycleBinFiles.txt
℡Ms空城旧梦 2024-07-23 12:57:09

我在这里找到了这个脚本
并使用我的批处理文件中的此命令来调用它,

cscript recyclebin.vbs >> "logs\recyclebin.txt"

将以下内容保存为 recyclebin.vbs

Option Explicit

Dim g_objWshShell, g_objFSO, g_sLogFile, g_objWshNetwork, g_sScriptName, g_sComputerName, g_sUserName
Dim g_sVer, g_objLogFile, g_sLogDir

'Setup main variables and objects
Set g_objWshShell = WScript.CreateObject("WScript.Shell")     'Create a Shell Object
Set g_objFSO = CreateObject("Scripting.FileSystemObject")     'create a File System Object
Set g_objWshNetwork = WScript.CreateObject("WScript.Network") 'Create Network Object
g_sComputerName = g_objWshNetwork.Computername                'Gets machine Computer name
g_sUserName = g_objWshNetwork.UserName                        'Gets logged-on username
g_sScriptName=UCase(WScript.ScriptName)                       '*** Name of the script

' *** START LogFile Information - use Delete or Append info below; don't use both ***
Const FORREADING = 1, FORWRITING = 2, FORAPPENDING = 8        'Setup constants for writing, appending, etc
g_sLogDir = "C:\TEMP"
If Not (g_objFSO.FolderExists(g_sLogDir)) Then
    g_objFSO.CreateFolder(g_sLogDir)
End If
g_sLogFile = g_sLogDir & "\" & Left(g_sScriptName, Len(g_sScriptName) - 3) & "LOG" 'Makes log file the SCRIPTNAME.Log
g_sVer = "1.0"

'To delete a logfile and create a new one each time script is ran
If g_objFSO.FileExists(g_sLogFile) Then
    g_objFSO.DeleteFile(g_sLogFile) 'Delete logfile if it exists.
End If
Set g_objLogFile = g_objFSO.CreateTextFile(g_sLogFile, FORWRITING) 'Setup the logfile for writing

Call Main()
Call ExitScript()

'Start main script HERE ***
Sub Main()
    Dim objRecycleBin, objFolderItems, objItem, strSpecialFolderName
    strSpecialFolderName = "Recycle Bin"
    'Call WriteLine("Starting " & g_sScriptName & " at " & Date & " " & Time, g_objLogFile)
    Set objRecycleBin = GetSpecialFolderObject(strSpecialFolderName)    'Get Special Folder based upon input name
    Set objFolderItems = objRecycleBin.Items()                'Get items within Recycle Bin
    For Each objItem In objFolderItems                        'Delete all items within Special Folder
        If (objItem.Type = "File Folder") Then                'Check for file type
            g_objFSO.DeleteFolder(objItem.Path)               'Delete Folders
        Else
            g_objFSO.DeleteFile(objItem.Path)                 'Delete Files
        End If
        WScript.Echo "Deleted " & objItem.Name
    Next
End Sub

'*-*-*-*-*- Start Subroutines here *-*-*-*-*-
'Returns SpecialFolder based upon name of folder
Function GetSpecialFolderObject(NameOfFolder)
    Dim objShellApp, i, objSpecialFolder
    Set objShellApp = CreateObject("Shell.Application")
    On Error Resume Next
    For i=0 To 40   '40 is highest value for special folders
        Set objSpecialFolder = objShellApp.NameSpace(i)
        If (StrComp(objSpecialFolder.Title, NameOfFolder, vbTextCompare) = 0) Then
            Set GetSpecialFolderObject = objSpecialFolder
            Exit For
        End If
    Next
    Err.Clear
End Function

'Closes logfile and exits script
Sub ExitScript()
    'Call WriteLine(Date & " " & Time & "; Completed " & g_sScriptName, g_objLogFile)
    If IsObject(g_objLogFile) Then
        g_objLogFile.Close
    End If
    Wscript.Quit
End Sub

Sub EndOnError(sErrorString)
    WScript.Echo sErrorString & vbCrLf & "Check " & Chr(34) & g_sLogFile & Chr(34) & " for details"
    Call WriteLine (sErrorString, g_objLogFile)
    WScript.Quit()
End Sub

'Shows usage if input is wrong
Sub ShowUsage()
    WScript.Echo g_sScriptName & " v" & g_sVer & " Empties Recycle Bin for logged on user" & vbCrLf _
        & vbCrLf & "USAGE: [CSCRIPT] " & g_sScriptName
    WScript.Quit
End Sub

'Writes to log
Sub WriteLine(ByVal strMessage, ByVal objFile)
    On Error Resume Next
    If IsObject(objFile) Then        'objFile should be a file object
        objFile.WriteLine strMessage
    Else
        Call Wscript.Echo(strMessage)
    End If
End Sub

I found this script here.
And use this command from my batch file to call it

cscript recyclebin.vbs >> "logs\recyclebin.txt"

Save the following as recyclebin.vbs:

Option Explicit

Dim g_objWshShell, g_objFSO, g_sLogFile, g_objWshNetwork, g_sScriptName, g_sComputerName, g_sUserName
Dim g_sVer, g_objLogFile, g_sLogDir

'Setup main variables and objects
Set g_objWshShell = WScript.CreateObject("WScript.Shell")     'Create a Shell Object
Set g_objFSO = CreateObject("Scripting.FileSystemObject")     'create a File System Object
Set g_objWshNetwork = WScript.CreateObject("WScript.Network") 'Create Network Object
g_sComputerName = g_objWshNetwork.Computername                'Gets machine Computer name
g_sUserName = g_objWshNetwork.UserName                        'Gets logged-on username
g_sScriptName=UCase(WScript.ScriptName)                       '*** Name of the script

' *** START LogFile Information - use Delete or Append info below; don't use both ***
Const FORREADING = 1, FORWRITING = 2, FORAPPENDING = 8        'Setup constants for writing, appending, etc
g_sLogDir = "C:\TEMP"
If Not (g_objFSO.FolderExists(g_sLogDir)) Then
    g_objFSO.CreateFolder(g_sLogDir)
End If
g_sLogFile = g_sLogDir & "\" & Left(g_sScriptName, Len(g_sScriptName) - 3) & "LOG" 'Makes log file the SCRIPTNAME.Log
g_sVer = "1.0"

'To delete a logfile and create a new one each time script is ran
If g_objFSO.FileExists(g_sLogFile) Then
    g_objFSO.DeleteFile(g_sLogFile) 'Delete logfile if it exists.
End If
Set g_objLogFile = g_objFSO.CreateTextFile(g_sLogFile, FORWRITING) 'Setup the logfile for writing

Call Main()
Call ExitScript()

'Start main script HERE ***
Sub Main()
    Dim objRecycleBin, objFolderItems, objItem, strSpecialFolderName
    strSpecialFolderName = "Recycle Bin"
    'Call WriteLine("Starting " & g_sScriptName & " at " & Date & " " & Time, g_objLogFile)
    Set objRecycleBin = GetSpecialFolderObject(strSpecialFolderName)    'Get Special Folder based upon input name
    Set objFolderItems = objRecycleBin.Items()                'Get items within Recycle Bin
    For Each objItem In objFolderItems                        'Delete all items within Special Folder
        If (objItem.Type = "File Folder") Then                'Check for file type
            g_objFSO.DeleteFolder(objItem.Path)               'Delete Folders
        Else
            g_objFSO.DeleteFile(objItem.Path)                 'Delete Files
        End If
        WScript.Echo "Deleted " & objItem.Name
    Next
End Sub

'*-*-*-*-*- Start Subroutines here *-*-*-*-*-
'Returns SpecialFolder based upon name of folder
Function GetSpecialFolderObject(NameOfFolder)
    Dim objShellApp, i, objSpecialFolder
    Set objShellApp = CreateObject("Shell.Application")
    On Error Resume Next
    For i=0 To 40   '40 is highest value for special folders
        Set objSpecialFolder = objShellApp.NameSpace(i)
        If (StrComp(objSpecialFolder.Title, NameOfFolder, vbTextCompare) = 0) Then
            Set GetSpecialFolderObject = objSpecialFolder
            Exit For
        End If
    Next
    Err.Clear
End Function

'Closes logfile and exits script
Sub ExitScript()
    'Call WriteLine(Date & " " & Time & "; Completed " & g_sScriptName, g_objLogFile)
    If IsObject(g_objLogFile) Then
        g_objLogFile.Close
    End If
    Wscript.Quit
End Sub

Sub EndOnError(sErrorString)
    WScript.Echo sErrorString & vbCrLf & "Check " & Chr(34) & g_sLogFile & Chr(34) & " for details"
    Call WriteLine (sErrorString, g_objLogFile)
    WScript.Quit()
End Sub

'Shows usage if input is wrong
Sub ShowUsage()
    WScript.Echo g_sScriptName & " v" & g_sVer & " Empties Recycle Bin for logged on user" & vbCrLf _
        & vbCrLf & "USAGE: [CSCRIPT] " & g_sScriptName
    WScript.Quit
End Sub

'Writes to log
Sub WriteLine(ByVal strMessage, ByVal objFile)
    On Error Resume Next
    If IsObject(objFile) Then        'objFile should be a file object
        objFile.WriteLine strMessage
    Else
        Call Wscript.Echo(strMessage)
    End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文