Directory Content doesn't work

I am trying to get the directory content but apparently it doesn't work.

This is my test code:

void setup() {

Serial.begin(9600);
if (!Serial)
;

Serial.println("Setup started");

Bridge.begin();

FileSystem.begin();

File d = FileSystem.open(".", FILE_READ);

if (!d) {
Serial.println("Error opening directory");
Serial.println("Setup halted");
while(true)
;
}

d.rewindDirectory();

File f = d.openNextFile();

while(f) {

if (!f.isDirectory())
Serial.println(f.name());

f.close();

//f = d.openNextFile();
}

d.close();

Serial.println("Setup Finished");
}

Issue 1: Any path I choose for FileSystem.open, d is always false. Apparently the function is not able to open any directory

Issue 2: I get a compilation error on f = d.openNextFile():

/Applications/Arduino_1.5.4.app/Contents/Resources/Java/libraries/Bridge/src/FileIO.h: In member function 'File& File::operator=(const File&)':
/Applications/Arduino_1.5.4.app/Contents/Resources/Java/libraries/Bridge/src/FileIO.h:28: error: non-static reference member 'BridgeClass& File::bridge', can't use default assignment operator
sketch_nov09a.ino: In function 'void setup()':
sketch_nov09a.ino:40: note: synthesized method 'File& File::operator=(const File&)' first required here

Can anyone help me fixing my code ?

Woudn't it be easier to use :

p.runShellCommand("ls -1");

Hi Erni,

thank you for your answer. Your suggestion is an option, but in this way there is a lot of post processing to do.

For example, I have to ignore directories. To exclude them from the list I have to issue a command like this:

ls -l . | egrep -v ^d

and unfortunately this return a lot of information about the file that have to be stripped off:

-rwxr-xr-x    1 root     root             5 Nov  9 14:13 goofy.txt

Probably, that is the reason why the file management functions exist. They should give a direct access to the file, its informations and its content.

I have find this command:

ls -p . | egrep -v /$

which returns just the information I need.

Anyway, I would prefer to access directories and files via the dedicated functions.

Hi fab64, it looks like an issue with the cpp part of the bridge. Can you open an issue on github? Issues · arduino/Arduino · GitHub