09-01-2015, 07:06 AM | #1 |
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,177
|
io.popen - is it working with Lua?
Hi.
I need to store table of all files in folder, for example /Reaper/Grooves. Cant get this works. Can anyone help? Code:
files_t = {} path = reaper.GetExePath().."\\Grooves" .."\\" for file in io.popen(path):lines() do table.insert(files_t, file) end I also tried this (don`t understand synthax, here could be something wrong), same error: Code:
io.popen([[dir "]]..path..[[" /b]]):lines() Last edited by mpl; 09-01-2015 at 08:56 AM. |
09-16-2015, 01:56 AM | #2 |
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,177
|
Upd: doesn't work with Reaper x86
|
09-16-2015, 02:44 AM | #3 |
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Doesn't work here but I don't even get an error message.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues. |
09-16-2015, 04:31 AM | #4 |
Administrator
Join Date: Mar 2007
Location: NY
Posts: 16,501
|
I don't think you want io.popen, you just want io.open. What your code is doing is trying to execute the list of files and read the output of that nonexistent program, instead of just reading the list of files.
http://www.lua.org/manual/5.3/manual.html#6.8 io.open and file:lines seem to be working properly. |
09-16-2015, 07:59 AM | #5 |
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,177
|
Popen works for me only with Reaper x 64.
Schwa, can you explain how to get list of files in directory, using io.open? What I need is just store filenames in directory to table, no need to read every file content, just names. |
09-16-2015, 08:59 AM | #6 |
Administrator
Join Date: Mar 2007
Location: NY
Posts: 16,501
|
Sorry, I thought you were opening a file that already contained a list of filenames. If you need to list the files within a directory, you will need popen, which is really just way to call a shell command and capture the output.
This should work on Windows. It's equivalent to opening a shell and executing "dir path /b". Other platforms will need different shell commands. Code:
path=reaper.GetResourcePath() .. "\\Grooves" filelist=io.popen('dir "' .. path .. '" /b') for filename in filelist:lines() do reaper.ShowConsoleMsg(filename ..'\n') end |
09-16-2015, 09:41 AM | #7 |
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Would be good if Reaper provided some direct APIs for these pain points...Frankly it's ridiculous one has to execute the operating system directory listing command as an external process to get the file names out of a directory!
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues. |
09-16-2015, 10:55 AM | #8 | |
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,177
|
Schwa, that is what I`m talking about
Quote:
(I`m on Win7x64) |
|
09-16-2015, 11:03 AM | #9 |
Administrator
Join Date: Mar 2007
Location: NY
Posts: 16,501
|
My code example works here on Windows 7 x86 and x64. But shell commands by definition won't be reliably portable. Like Xenakios says, the only way for this to be fully portable would be for us to add file management functions to the API.
Last edited by schwa; 09-16-2015 at 11:15 AM. |
09-16-2015, 11:20 AM | #10 |
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,177
|
Agree. Yes, native implementation of these things would be good.
Hmm, very strange, can`t get it works. Well, anyway, thanks. Just to say, I need this for my Quantize tool. To let user choose SWS groove from GUI list. If possible to get file from browser "Open file" window, please let me know. Thanks again! |
09-16-2015, 11:40 AM | #11 |
Administrator
Join Date: Mar 2007
Location: NY
Posts: 16,501
|
|
09-16-2015, 12:06 PM | #12 |
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 4,177
|
Wow, how could I missed that?! Thank you very much.
|
Thread Tools | |
Display Modes | |
|
|