Page 1 of 1
filename and subfolder
Posted: Thu Dec 22, 2016 4:19 am
by tusa
In a text field I need to show a name of a selected file, I do that like this:
Code: Select all
on mouseUp
answer file "Choose your graphic"
put it into graphicChoice
set the itemdelimiter to slash
put item -1 of graphicChoice into editedGraphicName
set itemdelimiter to "."
delete item 2 of editedGraphicName
put editedGraphicName into field tmplFile
end mouseUp
It returns "filename" in the field "tmplFile"
That is also correct, but if the file is placed in af subfolder, I need to show that too, as follows
"subfolder/filename"
But how do I do that?
Re: filename and subfolder
Posted: Thu Dec 22, 2016 11:44 am
by Klaus
Hi tusa,
question is, what defines a folder as a subfolder? What do you define as "parent" folder?
Know what I mean?
We need a reference that we can compare to the folder returned by the "anser file" dialog!
And what if that is not a "subfolder" (of whatever) but another folder on the users hard drive?
Best
Klaus
Re: filename and subfolder
Posted: Thu Dec 22, 2016 2:06 pm
by tusa
My thought was to make a field with the parent folder, like this (Skabelon bibliotek:):
In the 2 fields (Nu:/Næste:) I want to show the filename, like I do now, if the file is in that folder.
If the file is in a subfolder in the specefied folder, I want to show "subfoldername/filename"
Right now I use this code:
Code: Select all
on mouseUp
answer file "Vælg din grafik"
put it into graphicChoice
set the itemdelimiter to slash
put item -1 of graphicChoice into editedGraphicName
set itemdelimiter to "."
delete item 2 of editedGraphicName
put editedGraphicName into field now_tmpl_fileField
end mouseUp
Re: filename and subfolder
Posted: Thu Dec 22, 2016 2:16 pm
by Klaus
Hi tusa,
AHA!
Quick idea:
Code: Select all
on mouseUp
## Store reference folder:
put fld "Skabelon bibliotek" into tBib
answer file "Vælg din grafik"
put it into graphicChoice
set itemdelimiter to "."
delete item 2 of editedGraphicName
## Now my trick:
replace tBib with "" in graphicChoice
## ALWAYS put quotes around strings!
put graphicChoice into field "now_tmpl_fileField"
end mouseUp
Tested and works
Best
Klaus