Equivalence of Microsoft.VisualBasic.FileIO.FileSystem in C #

I am using VS 2008, .net 3.5, C # projects. I need to do the same as Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory.

Anyone says that linking to Microsoft.VisualBasic is often undesirable from C #. Any connection to VB from C # code amazes me as junk.

Using the FileSystem class is the perfect solution, but I prefer not to reference the Microsoft.VisualBasic library. That I would avoid.

     private static void DeleteDirectory(string destino)
            {
    //UIOption Enumeration. Specifies whether to visually track the operation progress. Default is UIOption.OnlyErrorDialogs. Required.

    //RecycleOption Enumeration. Specifies whether or not the deleted file should be sent to the Recycle Bin. Default is RecycleOption.DeletePermanently.

    //UICancelOption Enumeration. Specifies whether to throw an exception if the user clicks Cancel. Required.
                Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(destino, 
Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, 
Microsoft.VisualBasic.FileIO.RecycleOption.DeletePermanently, 
Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException);
                //Directory.Delete(destino, true);
            }

Other samples: How to place a file in the trash instead of deleting it?

Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(file.FullName,
    Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs,
    Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
+5
source share
4 answers

Within the namespace System.IO, the same / similar functionality is available:

System.IO.FileInfo fi = new System.IO.FileInfo("C:\\Test.txt");
fi.Delete();

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("C:\\Test");
di.Delete(true); //Recursive, pass false for no recursion.

SendToRecycleBin, :

di.MoveTo("C:\\$Recycle.Bin\\S-..."); //You'd need to know the SID of the user logged in


, :

try
{
    bool deletePermanently = true; //Set to false to move

    System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("C:\\Test");
    if (deletePermanently)
    {
        if (di.Exists)
            di.Delete(true);
    }
    else
    {
        if (di.Exists)
            di.MoveTo("C:\\$Recycle.Bin\\S-0-0-00-00000000-000000000-0000000000-000"); //Replace with your SID
    }
}
catch
{
    Console.WriteLine("Error deleting directory"); //Add exception detail messages...
}

, SID ​​.

+1

Directory.Delete, , , DeleteDirectory. , , , .

0

.

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("C:\\MyDirectoryToDelete");
di.Delete(true);

System.IO.Directory.Delete("Path goes here");

, .

0

System.IO Versus VisualBasic.FileIO

FileIO Microsoft.VisualBasic AFAIK, .

0
source

All Articles