Old 09-04-2015, 11:43 PM   #1
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,269
Default Get directory filelist with Lua io.popen - how?

ok, previously i posted this to a wrong developer forum (or not?) so I post this here again.


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
Error: "attempt to index a nil value"

I also tried this (don`t understand synthax, here could be something wrong), same error:
Code:
io.popen([[dir "]]..path..[[" /b]]):lines()
Can I do something with os.execute?
__________________
SoundCloud | MPL Scripts / ReaPack | Donate
mpl is online now   Reply With Quote
Old 09-05-2015, 12:26 AM   #2
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default

Maybe this helps (needs some editing to make it work correctly):

Get file names from current script path.lua

Code:
function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

function get_script_path()
  local info = debug.getinfo(1,'S');
  local script_path = info.source:match[[^@?(.*[\/])[^\/]-$]]
  --msg(script_path)
  return script_path
end

-- get "script path"
script_path = get_script_path()

-- Lua implementation of PHP scandir function
function scandir(directory)
    local i, t, popen = 0, {}, io.popen
    for filename in popen('dir "'..directory..'" /b'):lines() do
        msg(filename)
        i = i + 1
        t[i] = filename
    end
    return t
end

file_table = scandir(script_path)

--msg(package.path)
spk77 is offline   Reply With Quote
Old 09-05-2015, 12:43 AM   #3
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,269
Default

Same thing when appeal to io.popen -
Quote:
attempt to index a nil value
It needs value, ok. If I do something like
Code:
io.popen(directory)
I get
Quote:
attempt to call a nil value (local 'popen')
script_path is OK, to be clear. So, as i understood, reaper reads io.popen not as a LUA command, but as value in table.

This is I found also: http://www.promixis.com/forums/showt...-not-supported, it is about Lua 5.2, but now we have 5.3, so coult it be missing because of Lua limitations somehow?
__________________
SoundCloud | MPL Scripts / ReaPack | Donate

Last edited by mpl; 09-05-2015 at 12:57 AM.
mpl is online now   Reply With Quote
Old 09-05-2015, 01:14 AM   #4
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default

What happens if you remove the last "\\" ?
path = reaper.GetExePath().."\\Grooves" .."\\"




Just noticed that this works:
grooves_path = [[C:\Users\Pavillion 11\AppData\Roaming\REAPER\Grooves]]
(this is the path to SWS groove files on my computer)




Code:
function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

grooves_path = [[C:\Users\Pavillion 11\AppData\Roaming\REAPER\Grooves]]

-- Lua implementation of PHP scandir function
function scandir(directory)
    local i, t, popen = 0, {}, io.popen
    for filename in popen('dir "'..directory..'" /b'):lines() do
        msg(filename)
        i = i + 1
        t[i] = filename
    end
    return t
end

file_table = scandir(grooves_path)
spk77 is offline   Reply With Quote
Old 09-05-2015, 01:34 AM   #5
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,269
Default

That is really strange. I just replace my folder into script and got still the same error. And there is no any cyrillic sybols in path, backslash at the end or something.
Quote:
attempt to index a nil value
on line
Code:
    for filename in popen('dir "'..directory..'" /b'):lines() do
Hope it is not because i`m on win7
__________________
SoundCloud | MPL Scripts / ReaPack | Donate

Last edited by mpl; 09-05-2015 at 01:40 AM.
mpl is online now   Reply With Quote
Old 09-05-2015, 01:47 AM   #6
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default

I'm on Win8.1 64bit.

Made another test:
I made a folder (Grooves) and two files into it (Test file1.txt and Test file2.txt). "Grooves" folder is in the script path.


It's working for me :


Code:
function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

--p = reaper.GetExePath()
function get_script_path()
  local info = debug.getinfo(1,'S');
  local script_path = info.source:match[[^@?(.*[\/])[^\/]-$]]
  --msg(script_path)
  return script_path
end

-- get "script path"
script_path = get_script_path()
grooves_path = script_path .. "\\Grooves"

-- Lua implementation of PHP scandir function
function scandir(directory)
    local i, t, popen = 0, {}, io.popen
    for filename in popen('dir "'..directory..'" /b'):lines() do
        msg(filename)
        i = i + 1
        t[i] = filename
    end
    return t
end

--file_table = scandir(script_path)
file_table = scandir(grooves_path)
spk77 is offline   Reply With Quote
Old 09-05-2015, 01:57 AM   #7
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 1,269
Default

Variables is ok for me.

I also tried to run REAPER as administrator - same.

UPD. We find a bug.
Reaper 502pre3 x86 - doesn`t work
Reaper 502pre3 x64 - works.
__________________
SoundCloud | MPL Scripts / ReaPack | Donate

Last edited by mpl; 09-05-2015 at 02:10 AM.
mpl is online now   Reply With Quote
Old 09-16-2015, 03:28 PM   #8
semiquaver
Human being with feelings
 
Join Date: Jun 2008
Posts: 4,854
Default

I get "'popen' not supported" on mac 64 5.01b3
semiquaver is offline   Reply With Quote
Old 09-17-2015, 05:09 PM   #9
semiquaver
Human being with feelings
 
Join Date: Jun 2008
Posts: 4,854
Default @ devs: is io.popen supported on mac??

I get a message "'popen' not supported.

Trying to use external processes for text io

thx!

Mac Reaper64

Last edited by semiquaver; 09-17-2015 at 05:18 PM.
semiquaver is offline   Reply With Quote
Old 09-17-2015, 08:42 PM   #10
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,932
Default

It seems that the question was answered few posts ago ! :P
http://forum.cockos.com/showthread.php?t=166043

Sorry, wrong link, here is it is :
http://forum.cockos.com/showthread.php?t=165856
X-Raym is offline   Reply With Quote
Old 09-17-2015, 09:43 PM   #11
semiquaver
Human being with feelings
 
Join Date: Jun 2008
Posts: 4,854
Default

in that thread Schwa suggests that io.popen works fine and gives some windows code as an example...

... but here on mac I'm having no luck - so wondering if io.open is supported on windows only??

(the solution to mlp's problem doesn't solve mine sadly )
semiquaver is offline   Reply With Quote
Old 09-18-2015, 04:39 AM   #12
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 9,098
Default

Merged the threads. There may be a compile issue with enabling Lua's popen on OS X x64, we'll look at it.

For directory listing, this will be moot soon, as we have added file listing functions to the REAPER API for the next build.

For user input, there are a few basic functions in the API already.
schwa is offline   Reply With Quote
Old 09-18-2015, 04:46 AM   #13
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,505
Default

Quote:
Originally Posted by schwa View Post
...

For directory listing, this will be moot soon, as we have added file listing functions to the REAPER API for the next build.

...

Like the sound of that



>
planetnine is offline   Reply With Quote
Old 09-18-2015, 05:02 AM   #14
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 9,098
Default

... fixed popen on OSX for the next build, too.
schwa is offline   Reply With Quote
Old 09-18-2015, 05:14 AM   #15
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,932
Default

Oh yes that sounds very great, it open a lot of possibility !
Thanks
X-Raym is offline   Reply With Quote
Old 09-18-2015, 06:31 AM   #16
semiquaver
Human being with feelings
 
Join Date: Jun 2008
Posts: 4,854
Default

thanks Schwa !
semiquaver is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.