Page 1 of 1

Error with DIRLIST

Posted: August 7th, 2026, 3:10 am
by hannesrr
Hello friends,

I need your helps with DIRLIST FUNCTION. When I use DirList function on PC/Laptop, It's working, but when I use DirList function on Mobile Android it doesn't work.

That's is my code:

function ListarAudio()
List string displayList;
List string fileList;
string audioFolderPath = "../Audio"; // adapta según ruta real
numeric success;

success = dirlist(fileList, audioFolderPath, filter:="*.m4a", recursive:=true); //this code line doesn't work on mobile
//success = dirlist(fileList, audioFolderPath, filter:="*.*", recursive:=false); ---This code line works correct, but I need brought only *.m4a (audio files)
if fileList.length() = 0 then
errmsg("No se encontraron archivos de audio en " + audioFolderPath);

endif;

// Mostrar los archivos
numeric selIndex = fileList.show("Seleccione un archivo de audio");
if selIndex > 0 then
string selectedFile = fileList(selIndex);
// Aquí haces lo que necesites: reproducir, revisar, borrar, etc.
Audio aud;
aud.load(selectedFile);
aud.play();
endif;

end;


Attached:
View of audio files in my root of mobile
View of CsEntry in my mobile
AUDIO_FILES.PNG
CSENTRY - VIEW ON MOBILE.PNG

Re: Error with DIRLIST

Posted: August 7th, 2026, 4:48 am
by khurshid.arshad
Your project name is "Encuesta Mujeres - Mejoramiento de Justicia", and within this project folder you have a subfolder named "Audio".

Please use:

string audioFolderPath = "Audio";

instead of:

string audioFolderPath = "../Audio";

I tested this on both my Android device and my laptop, and it worked correctly.

I hope it works for you as well.

Re: Error with DIRLIST

Posted: August 8th, 2026, 9:00 pm
by hannesrr
Hello khurshid!

Thank for your answer.
But, I try to explain my issue.

I want the ListarAudio() function to locate and list the audio files (.m4a) recorded during the surveys, allowing them to be selected and played directly from the application. The central challenge is path location: the logic runs from the application hosted in the Menu folder, while the audio files reside in the Audio folder, a sibling of Menu within the same deployment root. That's why the path must be calculated dynamically by going up one level from Menu (..) and then into Audio, rather than relying on a fixed relative path ("../Audio") that assumes a specific working directory. The end goal is for this reference to work robustly regardless of where or how the application is invoked on the device.

Folder :
/ (root)
/Menu (App that calls ListarAudio functions)
/Audio (folder with the audio files *.m4a)

That is the reason to I use "/..Audio"

[RESOLVED] Re: Error with DIRLIST

Posted: August 8th, 2026, 11:29 pm
by hannesrr
title: dirlist() filter fails to match audio files recorded with Audio.save() — filename has trailing whitespace after the extension

Problem description:
When using dirlist() with a specific extension filter, for example:

cspro
dirlist(fileList, audioFolderPath, filter := "*.m4a", recursive := true);

the function returns no files, even though the folder clearly contains visible, accessible .m4a files. Switching the filter to "*.*" does return them.

Root cause identified:

The audio files are being generated with trailing whitespace after the extension, for example:

"nuevoarchivo.m4a "

(note the trailing space after .m4a). Since the actual filename doesn't end exactly in .m4a, the wildcard *.m4a fails to match it, while *.* still picks it up because it doesn't depend on where the name ends.

Likely source of the whitespace:

The trailing space is introduced when building the filename before calling Audio.save(), most likely due to:

Concatenating application variables (fixed-width dictionary items, maketext, etc.) that carry padding spaces (fixed-length text fields without strip()), or
A literal string with an accidental trailing space baked into the filename.

Thank for read!!