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
extracting the path only of a selected file.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 13
- Joined: Mon Aug 26, 2013 6:49 pm
extracting the path only of a selected file.
**************
Bruce
Bruce
Re: extracting the path only of a selected file.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 13
- Joined: Mon Aug 26, 2013 6:49 pm
Re: extracting the path only of a selected file.
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
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
Bruce
Re: extracting the path only of a selected file.
Hui Bruce,
you can have it shorter
Best
Klaus
you can have it shorter

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
...
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 13
- Joined: Mon Aug 26, 2013 6:49 pm
Re: extracting the path only of a selected file.
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!
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
Bruce