-
I need to retrieve a list of files from a directory. Tried without success: I don't want to use OS specific commands (dir, ls...) Thx in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
https://docs.juce.com/master/classFile.html#a5d2231468698548f2edde113235b3001 It reminds me of a StringAray to me. Like the one returned when you request the MidiInputs list (i struggled with):
I don't know if it's useful but I remind that you have to define an array beforehand, then you get the number of child with getNumChildren() and populate the array with the childs with getChild(i). There's a part in the source code in c++ where it uses the getChild(i) at line82 and below: This one is deprecated and shows the JUCE to LUA function findChildFiles at line34: This one is up to date and shows findChildFiles at line11: |
Beta Was this translation helpful? Give feedback.
-
Thank you Damien. a = {} In LFile.h, it is showing that a table is good Pretty sure it is just a syntax thing... dD:getNumberOfChildFiles(2,"*.txt") works fine |
Beta Was this translation helpful? Give feedback.
-
The first argument to the function actually points to a lua table through luabind. The function returns void. The function then fills the lua table with objects of type File (child files): void LFile::findChildFiles (luabind::object const& table, int whatToLookFor, bool searchRecursively, const String wildcardPattern) const { Array files; File::findChildFiles (files, whatToLookFor, searchRecursively, wildcardPattern); for (int i=1; i<=files.size(); i++) { table[i] = files[i-1]; } } ... so in lua you get; t = {} f = File ("c:\\devel") f:findChildFiles (t, File.findDirectories, true, "*") for i,v in ipairs(t) do console (v:getFullPathName()) end This is Atom's code. The directory to search is hardcoded. See solution below. |
Beta Was this translation helpful? Give feedback.
-
This is how would you do it with Directory selection: readFile = function() local f = utils.getDirectoryWindow("Search for Directory", File('')) local t = {} f:findChildFiles(t, 2, false, "*.txt") for i, v in ipairs(t) do console(v:getFullPathName()) end --print each found element in the table end |
Beta Was this translation helpful? Give feedback.
This is how would you do it with Directory selection:
findChildFiles_1_0_2021-12-26_18-00.zip