LeeC22 Posted February 17, 2021 Share Posted February 17, 2021 (edited) For anyone who writes any tools or mods that save files to disk and likes to add some fail-safe measures into that, this might be useful for you. Add a Reference to Microsoft.VisualBasic to your project. Add using Microsoft.VisualBasic.FileIO; in your class file. You now get the option to use FileSystem.Delete, which has the option to determine what happens to deleted files. One of which is this: FileSystem.DeleteFile(filename, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); That will send any deleted files to the Recycle bin, which is far safer than just deleting them forever. You do have a RecycleOption.DeletePermanently option if that's what you really want. As a bonus, you also get FileSystem.RenameFile, which makes far more sense than the C# hack of File.Move to rename a file. Filesystem.RenameFile works like this: FileSystem.RenameFile(oldFilenameIncludingFullPath, newFilenameWithoutAnyPathInfo); So this would be a valid statement: FileSystem.RenameFile(@"C:\SomeFolder\myFile.txt", "myNewFile.txt"); This would be an invalid statement: FileSystem.RenameFile(@"C:\SomeFolder\myFile.txt", @"C:\SomeFolder\myNewFile.txt"); Invalid because it has the full path on both sides. Edited February 17, 2021 by LeeC22 ikt and waynieoaks 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now