Old 03-07-2017, 03:19 PM   #1
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default another brilliant idea

maybe not brilliant but it IS an idea...

an action to open in a normal window a given reaper folder...
could be the color themes folder, or the grooves folder, or the folder where reaper is installed..

I'm imagining variations made by user changing the lua name and editing the path to a given folder with the exact path...

The use would be to more rapidly get to a given folder to work in there.

I do see where this could get tricky, especially when one has several instances of reaper installed, i.e. full, portable one, portable two, etc. and also tricky between PC and Mac installs... but thinking it might be possible for the user to edit a line that would be the path name...

Possible? or just crazy?
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-07-2017, 03:22 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Opening files in their native app is easy enough:

Code:
  local OS = reaper.GetOS()
  local path = "c:\my_text_file.txt"

  if OS == "OSX32" or OS == "OSX64" then
    os.execute('open "" "' .. path .. '"')
  else
    os.execute('start "" "' .. path .. '"')
  end
Give me a minute.

Edit: Folders work the same way, at least on Windows:

Code:
local path = "c:\\temp"

os.execute('start "" "' .. path .. '"')
Lokasenna is online now   Reply With Quote
Old 03-07-2017, 03:33 PM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Here's a couple to get you started. They'll be up on ReaPack shortly.

Lokasenna_Open Reaper folder
Lokasenna_Open Resource folder (this is where \ColorThemes, \Scripts, \Effects, etc live)

X-Raym also has one on ReaPack for opening the Project folder.
Lokasenna is online now   Reply With Quote
Old 03-08-2017, 01:28 AM   #4
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

Thanks Loka... fyi, had a few extra bucks today and they are pp to you... more when it comes cuz you certainly deserve it.

Those are nice starting points and will surely help...

and... is it possible to have a sort of generic lua, into which I could enter the path as it exists on my PC and have it open that folder in a window?

Obviously I can do this from various shortcuts which is what I now do... but it could be nice to get there directly... especially when doing things like working on theme pngs, etc.
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-08-2017, 03:45 AM   #5
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,376
Default

Lokasenna beat me to it.

I've had a bunch of toolbar buttons to open up various folders for ages. Really handy. Mine look like this...
Code:
import os
os.startfile(r"E:\Sound\REAPER\Autobackup")
(I'm on Windows)
IXix is offline   Reply With Quote
Old 03-08-2017, 05:42 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Quote:
Originally Posted by hopi View Post
and... is it possible to have a sort of generic lua, into which I could enter the path as it exists on my PC and have it open that folder in a window?
Yup. You'll have to choose one of two workarounds though, since Reaper doesn't let us open a "Choose a Folder" window:

a) Select a file in the folder you want.
b) Type the path in yourself.
Lokasenna is online now   Reply With Quote
Old 03-08-2017, 09:57 AM   #7
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

hmmm... ok and thanks to you both... but plz understand you are dealing with a real coding dummy here...

so for example, in that line that IXlx shows... is that it? Is that a complete lua script where I can just change the pointer to the directory?

Or do I need to include that line in some larger bunch of script???
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-08-2017, 10:05 AM   #8
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Yup, you can just paste any of those into a text file, change the path, change the extension to .lua, and you should be good to go.
Lokasenna is online now   Reply With Quote
Old 03-08-2017, 12:04 PM   #9
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,376
Default

Quote:
Originally Posted by hopi View Post
in that line that IXlx shows... is that it? Is that a complete lua script where I can just change the pointer to the directory?
Yeah, that's the whole script.
IXix is offline   Reply With Quote
Old 03-08-2017, 12:28 PM   #10
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

Hi - Would it need much additional code to have a script that inserts most recent file in a folder into reaper ?

Am looking to insert some video recorded at same time as some audio and this would save some dragging and media exploring.

Any tips welcome
BenK-msx is offline   Reply With Quote
Old 03-08-2017, 01:05 PM   #11
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

"most recent file" == the last file that was recorded?

I'm not sure how, but I think it's possible.
Lokasenna is online now   Reply With Quote
Old 03-08-2017, 01:23 PM   #12
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

Yeah the file in specified folder that is the newest, but filename based logic also doable. Will be looking into later in my machine..
BenK-msx is offline   Reply With Quote
Old 03-08-2017, 10:12 PM   #13
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 132
Default

Quote:
Originally Posted by BenK-msx View Post
Hi - Would it need much additional code to have a script that inserts most recent file in a folder into reaper ?

Am looking to insert some video recorded at same time as some audio and this would save some dragging and media exploring.

Any tips welcome
I was actually just working on a completely different script in which I needed to grab the Last Modified date of the file in a folder. If I'm not mistaken, this function should return the filename of the file with the most recent modified date in the folder:

Code:
function getLastModifiedFileFromFolder(folderPath)

	local filePath
	for file in io.popen([[dir "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
		filePath = folderPath.."\\"..file
		break
	end

	return filePath
end
I can't test it now but I think it works (On Windows. It won't work on Macs)
Claudiohbsantos is offline   Reply With Quote
Old 03-09-2017, 12:01 AM   #14
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

Quote:
Originally Posted by IXix View Post
Lokasenna beat me to it.

I've had a bunch of toolbar buttons to open up various folders for ages. Really handy. Mine look like this...
Code:
import os
os.startfile(r"E:\Sound\REAPER\Autobackup")
(I'm on Windows)

I'm on Window also... but don't know what I'm doing wrong
saved that as a .lua file, changed the "E:\...path" to the path I want

but it gives and error when run... a syntax error...
Is it meant to be a lua file, or something other?
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 12:09 AM   #15
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

well one of Lokasanas works to open the folder where my portable reaper is installed.... so that is good...

I still wish I could have a few others [variations] to open one of a few project folders, etc.

but I'm gonna try putting shortcuts to those in the reaper folder and see if that helps
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 03:05 AM   #16
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,376
Default

Quote:
Originally Posted by hopi View Post
Is it meant to be a lua file, or something other?
Sorry! I thought I had Lua'd those scripts but they're actually python! Embarrassing.
IXix is offline   Reply With Quote
Old 03-09-2017, 03:27 AM   #17
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,376
Default

Quote:
Originally Posted by hopi View Post
I still wish I could have a few others [variations] to open one of a few project folders, etc.
You can have as many as you want. Just change the path and save it as a new .lua file.

This works too (definitely lua this time )...
Code:
local path = "c:\\temp"
os.execute('explorer "' .. path .. '"')
or just...

Code:
os.execute('explorer "c:\\temp"')
IXix is offline   Reply With Quote
Old 03-09-2017, 11:45 AM   #18
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

IX thanks

I am getting errors... likely I'm doing something wrong...

here is one error:

OPEN _Color_Themes_Folder.lua:2: ')' expected near 'D'

here is the script that gives that error:

local path = "c:\\temp"
os.execute('explorer "'D:\Reaper 64 Portable\ColorThemes'"')

If I had a brain or understood better what the script commands mean, I could maybe get it working...

I'll try the other one in a minute

thanks for hanging in with me... I'd love to have a toolbar for opening locations while inside Reaper
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 11:50 AM   #19
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

no joy

on the other script, the more simple one, I get this error:

OPEN-Color Themes.lua:1: ')' expected near 'D'

this is the script:

os.execute('explorer "'D:\Reaper 64 Portable\ColorThemes"')
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 11:52 AM   #20
NextLevel
Human being with feelings
 
Join Date: Dec 2014
Posts: 410
Default

If you have the SWS extwnsion installed you can use this line to open a folder.

reaper.BR_Win32_ShellExecute("open", "", "", "F:\\Temp", 0)

or if you wanted to open a file within a folder it would look like.

reaper.BR_Win32_ShellExecute("open", "myfile.txt", "", "F:\\Temp\", 0)

Also there is an added bonus when using that api command, and that is no annoying console window.
NextLevel is offline   Reply With Quote
Old 03-09-2017, 01:14 PM   #21
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,376
Default

Quote:
Originally Posted by hopi View Post
os.execute('explorer "'D:\Reaper 64 Portable\ColorThemes"')
You've got mismatched quotes. You need a pair of outer ' and a pair of " around the path, like this...
Code:
'explorer "D:\Reaper 64 Portable\ColorThemes"'
...but in the two scripts you posted there are three ' and that's what causes the error. Until it hits a fourth ' the parser will assume everything is to be treated as a string literal.

Quote:
Originally Posted by NextLevel View Post
If you have the SWS extwnsion installed you can use this line to open a folder...
Thanks, I wasn't aware of that one. The API sprawls somewhat.
IXix is offline   Reply With Quote
Old 03-09-2017, 04:46 PM   #22
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

Quote:
Originally Posted by NextLevel View Post
If you have the SWS extwnsion installed you can use this line to open a folder.

reaper.BR_Win32_ShellExecute("open", "", "", "F:\\Temp", 0)

or if you wanted to open a file within a folder it would look like.

reaper.BR_Win32_ShellExecute("open", "myfile.txt", "", "F:\\Temp", 0)

Also there is an added bonus when using that api command, and that is no annoying console window.

Hey Next... I do have SWS installed... always

I'm not clear how to use what you have posted...

do I run that from something that SWS includes or do I create a file of some kind in scripts folder... or what exactly?
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 04:49 PM   #23
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

Quote:
Originally Posted by IXix View Post
You've got mismatched quotes. You need a pair of outer ' and a pair of " around the path, like this...
Code:
'explorer "D:\Reaper 64 Portable\ColorThemes"'
...but in the two scripts you posted there are three ' and that's what causes the error. Until it hits a fourth ' the parser will assume everything is to be treated as a string literal.


Thanks, I wasn't aware of that one. The API sprawls somewhat.
IX... well I'm feeling realling dumbass on this one... perhaps you can make it stupid easy for me?

Here is one path I want to open:

D:\Reaper 64 Portable\ColorThemes

Could just post the complete code that I can copy and save as a .lua file to do that? Thanks if you can...
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 04:53 PM   #24
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Code:
path = [[D:\Reaper 64 Portable\ColorThemes]]
os.execute('start "" "' .. path .. '"')
Use this and you don't ever have to worry about getting the 's and "s correct. Just make sure you've got the path inside a [[ and a ]].
Lokasenna is online now   Reply With Quote
Old 03-09-2017, 05:35 PM   #25
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,088
Default

Loka.... PERFECT! works like a charm and very easy for me to make variations for diff locations and get them into a toolbar... You Da Man!

I thank you so much for putting up with crazy old me.
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-09-2017, 05:36 PM   #26
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

I'm going to make one that automates it for you, so you just have to browse to a file and it makes a new script.
Lokasenna is online now   Reply With Quote
Old 03-09-2017, 05:42 PM   #27
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

cheers to Claudiohbsantos, but i'm a script dumby,

so Lokasenna old chap, how would i incorporate the below into your neat bit of code a post or two up to insert latest file? if its in any way faffy don't waste a thought on it, i'll just drag file from folder using that bit of code, its v quick really. cheers

Code:
function getLastModifiedFileFromFolder(folderPath)

	local filePath
	for file in io.popen([[dir "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
		filePath = folderPath.."\\"..file
		break
	end

	return filePath
end
I can't test it now but I think it works (On Windows. It won't work on Macs)[/QUOTE]
BenK-msx is offline   Reply With Quote
Old 03-09-2017, 05:52 PM   #28
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

I think you just need to add this after it:

Code:
 reaper.InsertMedia( filePath, mode )
There a bunch of different options for mode, some of which I'm not sure how to use - try just 0 for starters.

Quote:
mode:
0=add to current track,
1=add new track,
3=add to selected items as takes,

&4=stretch/loop to fit time sel,
&8=try to match tempo 1x,
&16=try to match tempo 0.5x,
&32=try to match tempo 2x,
&64=don't preserve pitch when matching tempo,
&128=no loop/section if startpct/endpct set,
&256=force loop regardless of global preference for looping imported items.
&512=use high word as absolute track index if mode&3==0.
Lokasenna is online now   Reply With Quote
Old 03-09-2017, 06:05 PM   #29
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

ooh! thanks alot, will try out now. -
edit: hmm as expected i failed at first try....

---
function getLastModifiedFileFromFolder(folderPath)

local filePath
for file in io.popen([[C:\Users\fakeuser\Videos "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
filePath = folderPath..""..file
break
end

return filePath

end

reaper.InsertMedia( filePath, 0 )

---

error says is expecting a string at the last filepath

if the reaper.insert... line is anywhere else get an error relating to 'end'.
or is my path info in the wrong place.

feel like a five year old asking why oranges are oranges or something, hope you guys are happy!

Last edited by BenK-msx; 03-09-2017 at 06:22 PM.
BenK-msx is offline   Reply With Quote
Old 03-09-2017, 07:55 PM   #30
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Oh, you have to actually call the function. As is, the function is being created, and then script is asking for filePath without actually getting filePath first, so Reaper says "hey, I don't know what you're talking about".

Code:
local folderPath = "whatever_your_folder_path_is"

function getLastModifiedFileFromFolder(folderPath)

  local filePath
  for file in io.popen([[C:\Users\fakeuser\Videos "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
    filePath = folderPath..""..file
    break
  end

  return filePath 

end

local filePath = getLastModifiedFileFromFolder(folderPath)

-- Error checking, always a good idea
if filePath and reaper.file_exists(filePath) then
  reaper.InsertMedia( filePath, 0 )
else
  reaper.ShowMessageBox("File doesn't seem to exist.\n\nPath: "..tostring(filePath), "Whoops", 0)
end
Lokasenna is online now   Reply With Quote
Old 03-09-2017, 08:17 PM   #31
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 132
Default

Quote:
Originally Posted by Lokasenna View Post
Oh, you have to actually call the function. As is, the function is being created, and then script is asking for filePath without actually getting filePath first, so Reaper says "hey, I don't know what you're talking about".

Code:
local folderPath = "whatever_your_folder_path_is"

function getLastModifiedFileFromFolder(folderPath)

  local filePath
  for file in io.popen([[C:\Users\fakeuser\Videos "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
    filePath = folderPath..""..file
    break
  end

  return filePath 

end

local filePath = getLastModifiedFileFromFolder(folderPath)

-- Error checking, always a good idea
if filePath and reaper.file_exists(filePath) then
  reaper.InsertMedia( filePath, 0 )
else
  reaper.ShowMessageBox("File doesn't seem to exist.\n\nPath: "..tostring(filePath), "Whoops", 0)
end
Thanks, that is perfect. Should have made it more clear how to use it.

Just a quick thing, the C:\Users\fakeuser\Videos should be in the place of "whatever_your_folder_path_is", and "dir "should be kept intact (that's the actual search command). The double slashes also needs to be kept because it completes the file path (the forum removes them for some reason if they are posted out of the code block)

so, with Lokasenna's additions, it would be:

Code:
local folderPath = "whatever_your_folder_path_is"

function getLastModifiedFileFromFolder(folderPath)

  local filePath
  for file in io.popen([[dir "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
    filePath = folderPath.."\\"..file
    break
  end

  return filePath 

end

local filePath = getLastModifiedFileFromFolder(folderPath)

-- Error checking, always a good idea
if filePath and reaper.file_exists(filePath) then
  reaper.InsertMedia( filePath, 0 )
else
  reaper.ShowMessageBox("File doesn't seem to exist.\n\nPath: "..tostring(filePath), "Whoops", 0)
end
Claudiohbsantos is offline   Reply With Quote
Old 03-09-2017, 08:50 PM   #32
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

you guys are hot...

will give a quick try now but its v late! many thanks tho


edit: boo - invalid escape sequence near "c:/users/ etc"

will come at this again tomorrow and nail it, apologies for being a pain.

Last edited by BenK-msx; 03-09-2017 at 09:00 PM.
BenK-msx is offline   Reply With Quote
Old 03-09-2017, 09:14 PM   #33
NextLevel
Human being with feelings
 
Join Date: Dec 2014
Posts: 410
Default

Quote:
Originally Posted by hopi View Post
Hey Next... I do have SWS installed... always

I'm not clear how to use what you have posted...

do I run that from something that SWS includes or do I create a file of some kind in scripts folder... or what exactly?
It's part of ReaScript.., the example I gave is in lua.
Just put it in a text file and save with the .lua extension, then load it into the actions list or a toolbar button.
NextLevel is offline   Reply With Quote
Old 03-09-2017, 09:19 PM   #34
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Quote:
Originally Posted by BenK-msx View Post
you guys are hot...

will give a quick try now but its v late! many thanks tho


edit: boo - invalid escape sequence near "c:/users/ etc"

will come at this again tomorrow and nail it, apologies for being a pain.
Escape sequences always refer to \s. On Windows, any \s in your path HAVE to be written as \\.
Lokasenna is online now   Reply With Quote
Old 03-09-2017, 09:55 PM   #35
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

Yo dawg, I heard you like scripts, so I made you a script that makes its own scripts so you can script while you script: http://forum.cockos.com/showthread.php?t=189152
Lokasenna is online now   Reply With Quote
Old 03-10-2017, 10:03 AM   #36
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

Code:
local folderPath = "whatever_your_folder_path_is"

function getLastModifiedFileFromFolder(folderPath)

  local filePath
---  next line has the error
  for file in io.popen([[dir "]]..folderPath..[[" /B /O:-D /A:-D]]):lines() do
    filePath = folderPath.."\\"..file
    break
  end

  return filePath 

end

local filePath = getLastModifiedFileFromFolder(folderPath)

-- Error checking, always a good idea
if filePath and reaper.file_exists(filePath) then
  reaper.InsertMedia( filePath, 0 )
else
  reaper.ShowMessageBox("File doesn't seem to exist.\n\nPath: "..tostring(filePath), "Whoops", 0)
end
ok.. think sorted the // 's issue on line 1 (every / replace with // right? ) but now getting 'attempt to index nil value' at line shown
thought that was to be left alone?

apologies for suckiness.
BenK-msx is offline   Reply With Quote
Old 03-10-2017, 04:37 PM   #37
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

flush with rugby victory, i'm up for nailing this mother and leaving you all to more important matters. any tips??
BenK-msx is offline   Reply With Quote
Old 03-10-2017, 04:47 PM   #38
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

This won't fix it, but it should at least give you a more intelligible error message. Error checking/handling is really important when working with files, I've found - it's easier to get an error, and often less obvious what you did wrong.

Code:
local folderPath = "whatever_your_folder_path_is"

function getLastModifiedFileFromFolder(folderPath)

  local filePath

  local f, err = io.popen([[dir "]]..folderPath..[[" /B /O:-D /A:-D]])

  if not f then
    reaper.ShowMessageBox("Error: "..tostring(err), "Whoops", 0)
    return 0
  end

  for file in f:lines() do
    filePath = folderPath.."\\"..file
    break
  end

  return filePath 

end

local filePath = getLastModifiedFileFromFolder(folderPath)

-- Error checking, always a good idea
if filePath and reaper.file_exists(filePath) then
  reaper.InsertMedia( filePath, 0 )
else
  reaper.ShowMessageBox("File doesn't seem to exist.\n\nPath: "..tostring(filePath), "Whoops", 0)
end
Lokasenna is online now   Reply With Quote
Old 03-10-2017, 05:18 PM   #39
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 5,639
Default

thanks - ok so that gives me:

error: dir "my path" [[" /B /O:-D /A:-D: no error


hmm.
BenK-msx is offline   Reply With Quote
Old 03-10-2017, 05:47 PM   #40
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,278
Default

The fact that it's including [[ in your path means you messed up a string somewhere.

It's working for me with a couple minor changes. One other issue, though, is that it will grab the most recent file regardless of type and try to insert it - in my case, it kept grabbing a .reapeak file from the folder I was using.

As you can see here, it's an easy fix.

Code:
local folderPath = [[F:\Muzik\Recordings]]

function getLastModifiedFileFromFolder(folderPath)

  local filePath

  local f, err = io.popen([[dir "]]..folderPath..[[" /B /O:-D /A:-D]])

  if not f then
    reaper.ShowMessageBox("Error: "..tostring(err), "Whoops", 0)
    return 0
  end

  for file in f:lines() do
	local ext = string.match(file, "%.(.*)$")
	if reaper.IsMediaExtension( ext, false ) then
		filePath = folderPath.."\\"..file
		break
	end
  end

  return filePath 

end

local filePath = getLastModifiedFileFromFolder(folderPath)

-- Error checking, always a good idea
if filePath and reaper.file_exists(filePath) then
  reaper.InsertMedia( filePath, 0)
else
  reaper.ShowMessageBox("File doesn't seem to exist.\n\nPath: "..tostring(filePath), "Whoops", 0)
end
Lokasenna is online now   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 07:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.