Old 06-04-2019, 01:30 AM   #1
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default reaper.file_exists in Mac OS X

This is working ok on Win but on Mac I can't get the path to work.

If I drag the wav in I get
Source properties
/Temp/Drums_120_.wav


but
if reaper.file_exists(open_file) then
won't work

if I manually enter the path
if reaper.file_exists("/Temp/Drums_120_.wav") then
it will work

if I
Msg("open_file string=".. open_file)
I get
open_file string= /Temp/Drums_120_.wav

I tried
tostring(open_file)
won't work
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-04-2019, 01:44 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,838
Default

Quote:
Originally Posted by MusoBob View Post
if I
Msg("open_file string=".. open_file)
I get
open_file string= /Temp/Drums_120_.wav
There's a space after the equal sign there. Where does open_file come from?
cfillion is offline   Reply With Quote
Old 06-04-2019, 03:23 AM   #3
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default

Sorry that was just a typo in the post, there is no space in the print out.
It just gets the wav filename from a txt file and looks in the current folder,
back one folder or back another. Whatever folder it finds the wav it sets that "file_source"
The Win part is working fine.

Code:
if os_type ~= "Win32" and os_type ~= "Win64" then
--Mac OS
   dir1 = string.gsub(filetxt, "/[^/]*$", "")
   dir = dir1 .."/"
   txt_filename1 = string.match(filetxt, "/[^/]*$")
   txt_filename = string.gsub(txt_filename1, "/", "")
   txt_filename_folder = string.gsub(wavename2, "_.*", "") -- remove _ and text after it
   blank_ext = string.gsub(txt_filename, ".txt", "")
   dir_back1 = string.gsub(dir1,"(.*)/.*$","%1")
   dir_back2 = string.gsub(dir_back1,"(.*)/.*$","%1")
   dir_back = dir_back1 .."/"
   txt_filename_folder2 = txt_filename_folder .."/"


else
--Win OS
   dir1 = string.gsub(filetxt, "\\[^\\]*$", "")
   dir = dir1 .."\\"
   txt_filename1 = string.match(filetxt, "\\[^\\]*$")
   txt_filename = string.gsub(txt_filename1, "\\", "")
   txt_filename_folder = string.gsub(wavename2, "_.*", "") -- remove _ and text after it
   blank_ext = string.gsub(txt_filename, ".txt", "")
   dir_back1 = string.gsub(dir1,"(.*)\\.*$","%1")
   dir_back2 = string.gsub(dir_back1,"(.*)\\.*$","%1")
   dir_back = dir_back1 .."\\"
   txt_filename_folder2 = txt_filename_folder .."\\"


end


  open_file = dir .. wavename2
  open_file_back = dir_back .. wavename2
  open_file_back2 = dir_back .. txt_filename_folder2 .. wavename2
 

  if reaper.file_exists(open_file) then file_source = open_file end
  
  if reaper.file_exists(open_file_back) then file_source = open_file_back end
  
  if reaper.file_exists(open_file_back2) then file_source = open_file_back2 end


  reaper.InsertMedia( file_source, 0 )
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-04-2019, 03:36 AM   #4
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default

Code:
  Msg("open_file ".. open_file)
  Msg("open_file_back ".. open_file_back)
  Msg("open_file_back2 ".. open_file_back2)

Console trace


open_file /Temp/Drums_120_.wav
open_file_back /Drums_120_.wav
open_file_back2 /Drums/Drums_120_.wav
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-04-2019, 03:58 AM   #5
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,838
Default

Are there really directories named Temp and Drums at the root (since these are absolute paths and it seems odd to put user files there)? Maybe the open_file variable contains newlines (since it comes from a file, and that would explain why typing the seemingly exact same absolute path manually works)?

Last edited by cfillion; 06-04-2019 at 04:07 AM.
cfillion is offline   Reply With Quote
Old 06-04-2019, 04:49 AM   #6
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default

That was just a Temp folder in the root, this is the folder, you can see it shows
the m4a in one folder back from the txt, second line of trace should be found and used as the "file_source" as it works on Win
Code:
if reaper.file_exists(open_file_back) then file_source = open_file_back end
Full Screen Pic


...
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-04-2019, 05:41 AM   #7
cyrano
Human being with feelings
 
cyrano's Avatar
 
Join Date: Jun 2011
Location: Belgium
Posts: 4,630
Default

What seems strange to me, is that all these folders and all these files seem to have an "accent circonflexe" eg, "^" in them.

Maybe these are composed from something else than "^" + space?

MacOS is very forgiving when using special characters in file names and paths, as long as you navigate those via the Finder. Once you access them from the Terminal, or via scripts, it's a different thing.

Simply test your script with a very short, clear path?

Alternatively, copy and paste that one character from the Finder into your script/txt file?
__________________
“It has become appallingly obvious that our technology has exceeded our humanity” Albert Einstein
cyrano is offline   Reply With Quote
Old 06-04-2019, 10:03 AM   #8
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default

Quote:
Originally Posted by cfillion View Post
.....Maybe the open_file variable contains newlines (since it comes from a file, and that would explain why typing the seemingly exact same absolute path manually works)?

using this I see there was a new line :

open_file = ("""..open_file..""")


Msg("open_file ".. open_file)
> open_file "/Applications/Band-in-a-Box/Drums/RockEven8/RockEven8_120_Style.m4a
"



so to remove space from the end I used to :

open_file = string.gsub(open_file, '^%s*(.-)%s*$', '%1')


Thanks !
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-04-2019, 10:52 AM   #9
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default

Quote:
Originally Posted by cyrano View Post
What seems strange to me, is that all these folders and all these files seem to have an "accent circonflexe" eg, "^" in them.

Maybe these are composed from something else than "^" + space?.....

the caret "^" is the next issue


Console trace
open_file /Applications/Band-in-a-Box/Drums/RockHardModernEv8^/RockHardModernEv8^1-ClsHt,QtrtHt/RockHardModernEv8^_120_Style.m4a
open_file_back /Applications/Band-in-a-Box/Drums/RockHardModernEv8^/RockHardModernEv8^_120_Style.m4a
open_file_back2 /Applications/Band-in-a-Box/Drums/RockHardModernEv8^/RockHardModernEv8^/RockHardModernEv8^_120_Style.m4a


if reaper.file_exists(open_file_back) then file_source = open_file_back end
won't work


but if I manually put
file_source = "/Applications/Band-in-a-Box/Drums/RockHardModernEv8^/RockHardModernEv8^_120_Style.m4a"
it works
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-04-2019, 11:12 AM   #10
cyrano
Human being with feelings
 
cyrano's Avatar
 
Join Date: Jun 2011
Location: Belgium
Posts: 4,630
Default

Let's hope that's the last issue...
__________________
“It has become appallingly obvious that our technology has exceeded our humanity” Albert Einstein
cyrano is offline   Reply With Quote
Old 06-04-2019, 03:27 PM   #11
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,086
Default

Quote:
Originally Posted by MusoBob View Post
so to remove space from the end I used to :

open_file = string.gsub(open_file, '^%s*(.-)%s*$', '%1')
Yes, but did you do that for the other folders ?
Code:
  open_file = string.gsub(open_file, '^%s*(.-)%s*$', '%1')
  open_file_back = string.gsub(open_file_back, '^%s*(.-)%s*$', '%1')
  open_file_back2 = string.gsub(open_file_back2, '^%s*(.-)%s*$', '%1')
Ahhh !#%^!


__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob 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 07:34 PM.


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