filename and subfolder

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tusa
Posts: 36
Joined: Sun Jan 31, 2016 10:30 pm

filename and subfolder

Post by tusa » Thu Dec 22, 2016 4:19 am

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?

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

Re: filename and subfolder

Post by Klaus » Thu Dec 22, 2016 11:44 am

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

tusa
Posts: 36
Joined: Sun Jan 31, 2016 10:30 pm

Re: filename and subfolder

Post by tusa » Thu Dec 22, 2016 2:06 pm

My thought was to make a field with the parent folder, like this (Skabelon bibliotek:):
Udklip2.JPG
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

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

Re: filename and subfolder

Post by Klaus » Thu Dec 22, 2016 2:16 pm

Hi tusa,

AHA! :D

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 :D


Best

Klaus

Post Reply