list filenames in the recyclebin with c# without using any external files

前端 未结 1 614
春和景丽
春和景丽 2021-01-06 05:32

I would like to have a function which retrieves me the filenames in the recycle bin (on win 7) with usage of c# code. The framework seems nothing to contain to achieve this.

相关标签:
1条回答
  • 2021-01-06 05:57

    If you add a reference C:\Windows\System32\Shell32.dll to in your application you can easily access the filenames of the files in the Recyle Bin

    Example:

        using Shell32;
    
        public IEnumerable<string> GetRecycleBinFilenames()
        {
            Shell shell = new Shell();
            Folder recycleBin = shell.NameSpace(10);
    
            foreach (FolderItem2 recfile in recycleBin.Items())
            {
                // Filename
                yield return recfile.Name;
    
                // full recyclepath
                // yield return recfile.Path;
            }
    
            Marshal.FinalReleaseComObject(shell);
        }
    

    If the extra file created bothers you you can embed it in the executable

    enter image description here

    0 讨论(0)
提交回复
热议问题