extracting the path only of a selected file.

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
Bruce Brown
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Mon Aug 26, 2013 6:49 pm

extracting the path only of a selected file.

Post by Bruce Brown » Wed Oct 02, 2013 2:59 am

I am writing a very simple program that allows a user to select a file then in a number of copies field
it will copy the file to the same directory as default but will also allow the user to select a different directory if they wish.
The Gui is simple:
Select file
Display filename only in field of file selected. In directory field put the path of file originally selected.
In the number of copies field which has default of 1
Do it button that copies the file and appends the copy count to original filename so.
Here is the code for my browse button for selecting the file. I don't know how to select the path before the filename.
The part in < > is the command necessary to select all items of path except the last item.
I should know this by now but have not had anytime to play (learn).

on mouseUp
## Ask the user to choose a file
answer file "Please choose a file"
## If the dialog is not cancelled put the path to the selected file into a variable
if the result is not "cancel" then
put it into tFilename
set itemDelimiter to slash
put last item of tFilename into field "file2Dupe"
put <path of original file> tFilename into field "outputDirectory"
end if
end mouseUp
**************
Bruce

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: extracting the path only of a selected file.

Post by dunbarx » Wed Oct 02, 2013 5:21 am

I am not sure I understand what you want, but could it be that you wish to:

put item 1 to -1 of it into fld "outputDirectory"

?

If this does it, can you think of another way to do this using the "number of items of it"?

Craig Newman

Bruce Brown
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Mon Aug 26, 2013 6:49 pm

Re: extracting the path only of a selected file.

Post by Bruce Brown » Sat Oct 05, 2013 4:56 pm

Hi I did not get back to this until today but you jogged my memory of the syntax.
Here is the correct code that works!
on mouseUp
## Ask the user to choose a file
answer file "Please choose a file"
## If the dialog is not cancelled put the path to the selected file into a variable
if the result is not "cancel" then
set itemDelimiter to slash
put number of items of it into pathLength
put last item of it into field "file2Dupe"
put item 1 to pathLength-1 of it into field "outputDirectory"
end if
end mouseUp
**************
Bruce

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: extracting the path only of a selected file.

Post by Klaus » Sat Oct 05, 2013 5:06 pm

Hui Bruce,

you can have it shorter :D

Code: Select all

...
if the result is not "cancel" then
  set itemDelimiter to "/"
  put item -1 of it into field "file2Dupe"
  put item 1 to -2 of it into field "outputDirectory"
end if
...
Best

Klaus

Bruce Brown
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Mon Aug 26, 2013 6:49 pm

Re: extracting the path only of a selected file.

Post by Bruce Brown » Thu Oct 10, 2013 1:32 am

Hi Klaus,
I forgot to say thank you. You nailed it. My program is complete and works great. Small insignificant it is but got to start somewhere!
**************
Bruce

Post Reply