Page 1 of 1

Looking up a file pathname

Posted: Tue Jan 03, 2017 9:54 am
by Timothy
I have a folder full of sound files that are necessary for a stack I'm working on. It's working now on my machine, but I'd like to be able to give the stack and sound files to others, and that means I want them to work on other machines.

To do that, I want to use a script to establish the pathName (or is it called filepath?) for the folder full of sounds.

I think there's a way to do this, but I don't know how. There are a couple of necessary commands or functions I don't know.

--Click on a button
--I get a dialog box showing a directory of my hard drive.
--I navigate through the directory until I find the file or folder I want, select it.
--The long pathname of the file or folder gets returned somehow
--I can store the pathname in a field or something, so when the stack is first used on a new machine, a script will be able to find the designated file or folder
--If the script is unable to find the right folder, the user is prompted to identify it, as above.

I don't need all the details, just a few hints. If someone can give me the general idea, I'd sure appreciate it.

I'm on Mac OS, current version, LC Community Edition, version 8.1.2.

Thanks in advance,

Tim

Re: Looking up a file pathname

Posted: Tue Jan 03, 2017 10:58 am
by dave.kilroy
Hi Tim - hopefully the following will give you some ideas:

Code: Select all

on checkForSoundFiles
     put the uSoundFiles of the current stack into tFolder
     put tFolder & slash & "fileThatIsAlwaysPresent.wav" into tFile
     if there is not a file tFile then 
          answer "Unable to find Timothy's Sound Files!"
          answer folder "Find Timothy's Sound Files"
          if the result is empty then
               put it into tFolder
               put files(tFolder) into tList
               if there is a file (tFolder & slash & "fileThatIsAlwaysPresent.wav") then 
                    set the uSoundFiles of the current stack to tFolder
                    answer "All OK now"
               else 
                    answer "file" && quote & "fileThatIsAlwaysPresent.wav" & quote && "not found"
               end if
          end if
     end if
end checkForSoundFiles
You could then call this handler in 'preOpenStack' or similar.

However if you'll be distributing your project as a standalone to other computers you won't be able to save the folder path as you would with a stackfile - you'll have to use a little text file (or similar) to save the folder path instead of a custom property or field.

Dave

Re: Looking up a file pathname

Posted: Tue Jan 03, 2017 10:47 pm
by Timothy
Thanks so much Dave.

Your suggestion will work just fine, of course, and I appreciate your detailed script. If I understand your script correctly, I am looking for something slightly different.

Let's say I have already manually copied the folder containing the sound files to the new machine's hard drive. I want the script to be able to find that folder.

I want to write a script that will show me the directory of the new hard drive, allow me to identify the folder in question and return the path name of that folder. I'll put it into a field or something for use in a script that will find the folder containing the sound files when needed. I don't need a detailed script, just a suggestion for the commands and functions I might need to to this.

Re: Looking up a file pathname

Posted: Tue Jan 03, 2017 11:12 pm
by SparkOut
It's in there above:

Code: Select all

answer folder "Find Timothy's Sound Files"
the script does a little more to check that the user didn't click the cancel button and various other helpful things, but this is the important line for you to check in the dictionary

Re: Looking up a file pathname

Posted: Wed Jan 04, 2017 4:40 am
by Timothy
Okay, I understand now. I'll explore those LC features. Thanks again.

T'im