Getting File Listing in a Directory

Online Status

I have been playing with the dos.library to get a listing of files in a directory.

I have been able to create a
directory_lock = Lock("location/directory", ACCESS_READ)

I create a structure FileInfoBlock file_info.

I do: Examine(directory_lock, &file_info)

I can see the file name is file_info.fib_EntryType, I see its type 2 in file_info.fib_DirEntryType which look like ST_Userdir as expected.

When I do a ExNext(directory_lock, &file_info) I get a return type of 0 which I am not expecting as I have a file inside the directory.

Calling IoErr() I get a return of type 232 which is where I am confused since that looks like no more entries.

I am fairly sure I did something silly somewhere...
The question is what magic am I missing to get the listing of files with in the directory?

Thank you

Online Status

Whelp slight better or worse. I was not looking at the file_info structure and I see the first file name in the directory. Oops.

But it does seem to stop when looping over the ExNext and not show me the second file name that is in the directory.

Disregard debug_print its some logging function I am doing.

int get_file_list(Email **file_list, char *file_path) {
int result = 1;
struct FileInfoBlock *file_info_block = AllocDosObject(DOS_FIB, NULL );

BPTR directory_name_lock = Lock(file_path, ACCESS_READ);

if ( directory_name_lock ) {
debug_print(20, "%s\n", "Get data directory");

if (Examine(directory_name_lock, file_info_block)) {
debug_print(20, "%s - %s - %ld - DIR Type: %ld\n", "Get file info",
file_info_block->fib_FileName, file_info_block->fib_EntryType, file_info_block->fib_DirEntryType);

debug_print(20, "File Name: %s\n", file_info_block->fib_FileName);

while (ExNext(directory_name_lock, file_info_block) ) {
debug_print(20, "%s\n", file_info_block->fib_FileName);

if (file_info_block->fib_EntryType == ST_FILE) {
debug_print(20, "%s\n", file_info_block->fib_FileName);
}
}
}
UnLock(directory_name_lock);

} else {
debug_print(20, "%s\n", "Error getting file info");
}

FreeDosObject(DOS_FIB, file_info_block);
return result;
}

Online Status

And now time to goto bed. It works as expected after a user error and an emulation error.

Me learning real time...

Online Status

There's code you could look at for doing this in Report+ (f8.c file), and probably in the RKM too, but you seem to have it sorted out now anyway :-)

Online Status

You are doing an if on fib_EntryType
That one is depricated you should use fib_DirEntryType even though I've never experienced any difference myself
That same if test could also be why your second file is filtered away if it happens to be a link ?

Other than that I can't see any problem with your code