I am using an ESP32-WROOM-32D (it says ESP32-DevKitC V4 on the back
) and I tried to program a sort of file navigator via the Serial Console in the IDE to interface a SPI SMT SD Card since you can't plug them into your pc directly. Anyways I started by simulating the code in WOKWI and the printDirectory function works fine but anything with creating or removing files and directories won't work. I have also rebuild this exact setup IRL but it seams to fail in the exact same way. Is this a problem between the sd library and the esp32?
Can you be a bit more specific about how it fails?
Looking at the code you linked on WOKWI, I did wonder about this line in void exec() and the case3 statement:
if(SD.mkdir(command.substring(command.indexOf(' ')+1))){
You are substring-ing from the position of the space to the end of the line, but you might need to deal with the whitespace characters (CR,LF) at the end of the line with trim();
You also have a similar statement in case4.
Thanks for pointing that out. This was actually a relic of the code before I revised it slightly. That part should have been replaced with "commandCtx1". The way the command structure should work is with a first initial command "mainCommand" and then a first subcommand "commanndCtx1" separated by a space and then a second subcommand "commandCtx2" witch would hold the entire rest of the entered command after the second space.
The function still doesn't work though. It just fails to create a directory in the case of mkdir().
Also not quite sure what you mean by whitespace characters. The "\n" at the end of a Serial.read should have been removed with the Serial.readStringUntil('\n'), right?
I also added a notation about how to write these commands behind the commands from line 6 onwards ![]()
Yes, readStringUntil() reads "up to" the termination charcter which is then discarded. So long as your string is terminated with only a newline and not CRLF (as, for ewample, is usually the case on Windows systems) then your text should be clean.
Can I ask, when you specify the filename, do you specify the full path to the file?
I actually don't really know how the SD library handles this. As I understand it, you enter a file name (like: "example.txt") but you can also open directories ("/"). But I'm not quite sure.
Its been a while since I worked with a SD card reader, but the reason I asked is that I seem to recall that when one did a file operation one had to specify the full path to the file. If the file is in the root then it shouldn't be a problem, but if its in a directory, then an action such as create or delete needs the full path. One can keep track of the current directory and add it to the filename before performing an action on the file.
As I say, its been a while before I worked with SD so maybe someone has a more recent experience and can advise.
I think I figured it out! you were actually right in front of every filename there has to be a / to complete the path. Don't know why you would have to do this but it works now I guess ![]()
Unix/Linux style path notation. There is no C: drive like in Windows. 'The symbol / signifies root, so /filename.txt would be a file in the root directory. Further down the directory structure it would be /path/to/dir/with/filename.txt. Sorry, I should have made it clear that files in the root directory should be preceded with a /. Glad you figured it out though.