0

I'm trying to make an app to "Quick Format" an usb flash drive, it's all good until i put a file without extension (eg: helloworld).

I'm using Directory.Delete(dir, true); to achieve my goal, but recursive delete is interpreting helloworld as a directory instead of interpreting it as a file, so it throws Access to the path 'helloword' is denied.

Any help will be appreciated!

Yak0d3
  • 1
  • 3
  • 1
    Your assumption is wrong. Directory.Delete is not confused by a filename without extension. The problem is in the permissions required to delete that file – Steve May 16 '18 at 20:08
  • Directory.Delete is deleting everything except `helloworld`, even though i can delete `helloworld` with File.Delete, but with recursive Directory.Delete i get this error – Yak0d3 May 16 '18 at 20:13
  • How are you determining that helloworld is a directory as opposed to a file? – glenebob May 16 '18 at 20:13
  • IIRC, you'd see the same error if the file is locked by another application - I think I've even seen it cause by an antivirus ... – Sam May 16 '18 at 20:18
  • Thank you for your replies, but `helloworld` is a sample file, it's not open somewhere else, plus i don't use antiviruses – Yak0d3 May 16 '18 at 20:21
  • Sorry to be that guy but.... it works on my machine – Dave May 16 '18 at 21:20
  • and as someone has said Directory.Delete is not confused by a lack of file extension. Something must be locking the file – Dave May 16 '18 at 21:23
  • Does `File.Delete(dir\helloworld);` delete the file successfully or does it fail as well? Are you sure the file isn't [read-only](https://stackoverflow.com/a/11523266/4934172)? – 41686d6564 stands w. Palestine May 17 '18 at 04:32

0 Answers0