Looking up a file pathname

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Looking up a file pathname

Post by Timothy » Tue Jan 03, 2017 9:54 am

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
It's better to be happy and rich than poor and sad -- W. C. Fields

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Looking up a file pathname

Post by dave.kilroy » Tue Jan 03, 2017 10:58 am

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
"...this is not the code you are looking for..."

Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Re: Looking up a file pathname

Post by Timothy » Tue Jan 03, 2017 10:47 pm

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.
It's better to be happy and rich than poor and sad -- W. C. Fields

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Looking up a file pathname

Post by SparkOut » Tue Jan 03, 2017 11:12 pm

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

Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Re: Looking up a file pathname

Post by Timothy » Wed Jan 04, 2017 4:40 am

Okay, I understand now. I'll explore those LC features. Thanks again.

T'im
It's better to be happy and rich than poor and sad -- W. C. Fields

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”