Delete a file from folder c#
Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Delete String Method Reference Is this page helpful? Please rate your experience Yes No. Any additional feedback? Download Microsoft Edge More info. Contents Exit focus mode. Delete Method Reference Is this page helpful?
Please rate your experience Yes No. Any additional feedback? Namespace: System. IO Assemblies: mscorlib. Deletes a specified directory, and optionally any subdirectories. Delete String. Deletes an empty directory from a specified path. This directory must be writable and empty. Applies to. Delete String, Boolean. Or use a using statement, where the File. Delete would go outside the brackets.
In the example you have, you should also do a filestream. Dispose ;. Hameed Syed Hameed Syed 3, 2 2 gold badges 16 16 silver badges 27 27 bronze badges. So you are trying to delete file 20 times per second until it's deleted. What if, for some reason, file can't be deleted and program will try to delete it forever?
I don't think this is good solution. At the very least, you should provide a timeout parameter. I think you should try for a limited time and return a failure message if the file wasn't deleted. Delete Path. Combine rootFolder, authorsFile ; Console. WriteLine "File deleted. Delete file ; Console. This will be the simplest way, if System. Delete filePath ; System. Another way I did is, if System. Collect ; System. WaitForPendingFinalizers ; System. Aniyan Kolathur Aniyan Kolathur 53 10 10 bronze badges.
The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.
0コメント