SdFat - Concise code to deletye all files from a folder / directory

Status
Not open for further replies.

Experimentalist

Well-known member
SdFat - Concise code to delete all files from a folder / directory

Hi

I am still struggling really to understand best practices when using the C language and I am looking for a concise way to perform the equivalent of the DOS cmd "Del *.mac" (Sorry I work entirely in the MS Windows environment) using the SdFat library http://code.google.com/p/sdfatlib/. At the moment all my files are stored in the root of the SD card, though I will shortly be looking to organise them into folders.

Up until now the easiest option for me has been to reformat my SD card when reprogramming my T3 since all the files are encrypted using keys stored on the EEPROM that are wiped out on re-programming. I now wish to retain some files so formatting is not the best option. The main reason for the change is that I am using a TFT LCD with the UTFT library http://henningkarlsen.com/electronics/library.php?id=52 and I use a lot of icons and graphics which I have started to serialise and de-serailise from the SD card to save memory

I wholly admit to being overwhelmed by pure C / C++ programming and come from a self taught .Net VB (originally) and C# (more recently) background. I am truly a novice programmer on a steep learning curve.

Any advice anyone can offer on the concise and correct way to achieve my aim is much appreciated

Ex.

p.s. I am sorry for those that find the question tedious :0)
 
Last edited:
p.s. I am sorry for those that find the question tedious :0)
I could use that in my signature I'm afraid :(
I am in a similar position, finding myself in a subject of astronomical proportions, and each answer comes with another 2 (or more!) new questions...

Anyway, this post describes what you want (by the author of the library himself).

You might want to add something like:
Code:
    if (!sd.chdir(folder)) {
      sd.errorHalt("chdir failed.");
    }
to move out of the root of the SD first.

Also, remember to change back to the root afterwards, that took me a while to realize :x
Code:
    if (!sd.chdir("/")) {
      sd.errorHalt("return to root failed.");
    }

Hope it helps!
 
Forgot to mention something quite important:

That code will remove all contents of the current working directory including subdirectories!
The only other code I know of capable of removing files would be sd.remove(), and deleting the files one at a time in a while/foreach loop.
 
Status
Not open for further replies.
Back
Top