I have a button in my program that will delete a certain file when clicked, such as example.txt. The code I have to delete it is:
File.Delete("example.txt")
But the file is still there. I have done some research and most people say that it should work. Why is this not working? Or is this code wrong?
To delete a text file and ask the user to confirm that the file should be deleted. Use the DeleteFile method to delete the file, setting showUI to AllDialogs . The following code demonstrates how to delete the file named test. txt and allow the user to confirm that the file should be deleted.
In VBA, we can delete any file present in the computer using VBA codes. The code used to delete files is known as the “Kill” command. The method to delete any file is that first, we must provide the file's path, which means the file's location on the computer. Then, we use the “Kill” command to delete the file.
This one doesn't require so much mystery :)
My.Computer.FileSystem.DeleteFile(ADDRESS_OF_FILE_AS_STRING)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With