System.ArgumentException trying to delete file in SD card

Hi everybody. I hope somebody can help me with this. I can’t delete a file with a malformed name. For unknown reasons the file got a name that is rejected by System.IO.dll and now it is impossible to read it or delete it. The filename has invalid (non display) characters.

File.Delete(path) gives a System.ArgumentException and Directory.Delete(path,true) gives a System.IO.IOException.

I’m pretty sure I could delete it if I put the SD in my PC, but I need to be able to cope automatically with this situation when the hardware be installed at the field.

Thanks a lot beforehand.

If this is the result of corruption and not a file that was written with that name, then you may have deeper problems than just the filename. Maybe the filename isn’t what is causing the exception. Maybe other filesystem structure corruption is causing the exception. In such a case, formatting is the only sure cure.

And if this is a data logger, using filenames is not a very robust way to log data unless you have protection against power interruptions. I tend to use a single file with an always-consistent combination of data structure and write semantics

@ mcalsyn - We do have protection against power failures but we are intently not using it during this testing phase. Most probably it was a power interruption that caused the corruption.

As the files contain no critical data I think I’ll send an alert to the server, format the SD and automatically download the files later.

Thanks a lot for your help!

1 Like