Putting Folder Names/Contents Into A Variable.

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

Putting Folder Names/Contents Into A Variable.

Post by Googie85 » Sun Oct 28, 2018 5:49 am

Could anyone help me with putting folder contents into a variable?

Many Thanks,

Googie,

jmburnod
VIP Livecode Opensource Backer
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.

Post by jmburnod » Sun Oct 28, 2018 9:43 am

Hi Googie,
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
Best regards
Jean-Marc
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
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.

Post by FourthWorld » Sun Oct 28, 2018 10:21 am

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Putting Folder Names/Contents Into A Variable.

Post by bogs » Sun Oct 28, 2018 2:32 pm

Jean-Marc's solution is excellent, but to answer your question directly -
Googie85 wrote:
Sun Oct 28, 2018 5:49 am
Could anyone help me with putting folder contents into a variable?
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
This is the result -
Selection_079.png
Files from a folder in a variable...
The new parameters Richard mentions make it a little shorter, maybe -

Code: Select all

answer folder "open"
put files(it) into tmpList
filter tmpList without ".*"
answer tmpList
Selection_081.png
The new way...
Image

Post Reply

Return to “Windows”