Could anyone help me with putting folder contents into a variable?
Many Thanks,
Googie,
Putting Folder Names/Contents Into A Variable.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Putting Folder Names/Contents Into A Variable.
Hi Googie,
I use this:
Best regards
Jean-Marc
I use this:
Code: Select all
on doChooseFolder
answer folder "open"
if it = empty then exit doChooseFolder
put LesFilesInFol(it) into tFiles
put tFiles
end doChooseFolder
function LesFilesInFol tFol -- return the list of files in a folder without ".*"
put empty into rLesFilesInFol
if there is a folder tFol then
put the Folder into tOldDF
set the Folder to tFol
put the files into rLesFilesInFol
set the Folder to tOldDF
filter rLesFilesInFol without ".*"
end if
return rLesFilesInFol
end LesFilesInFol
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9824
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Putting Folder Names/Contents Into A Variable.
In v9 new params have been added to the files function to allow you to get a list of files in a specified folder:
Code: Select all
put files([<targetFolder>, [short|long]])
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Putting Folder Names/Contents Into A Variable.
Jean-Marc's solution is excellent, but to answer your question directly -
This is the result -
The new parameters Richard mentions make it a little shorter, maybe -
All you really need (which I assume you have) is the folder you want the list of files from. The code is a couple of lines -
Code: Select all
// the folder you want to get the files from, in this case, I set the defaultFolder...
set the defaultFolder to "The folder you want the files from"
put the files into tmpList
// if you want *all* the files, hidden or no, omit the next line...
filter tmpList without ".*"
// use your variable, in this case I used answer...
answer tmpList
Code: Select all
answer folder "open"
put files(it) into tmpList
filter tmpList without ".*"
answer tmpList