ho can I read out the filenames in a directory and use them (maybe in an array)?
I used C# before

I need to read out a directory to use the filenames to open pictures for a slideshow.
Thank you

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
See here:DevBoyLars wrote:Hi there,
ho can I read out the filenames in a directory and use them (maybe in an array)?
Code: Select all
put 0 into tInc
repeat for each line tFile in the files
add 1 to tInc
put tFile into tList[tInc]
end repeat
answer "First file: " & tList[1] &cr& "Last file:" & tList[tInc]
Sounds great. Jus to be sure: You put tFile into the array. How does LiveCode knows on which position it is, when it puts a filename into the array on position tInc?Neurox66 wrote:Hi,
PaoloCode: Select all
put 0 into tInc repeat for each line tFile in the files add 1 to tInc put tFile into tList[tInc] end repeat answer "First file: " & tList[1] &cr& "Last file:" & tList[tInc]
Yes, but it is less elegantIs there another more LC way to do that without an array?
Code: Select all
local sAllFilesImg,sCurfolder
on GetImagesFiles
answer folder "Open an images folder"
put it into sCurfolder
set the defaultfolder to sCurfolder
get the files
filter it without ".*" -- take off file ".DS_Store"
put 0 into tInc
put empty into sAllFilesImg
repeat for each line tFile in it --the files
add 1 to tInc
put tFile & cr after sAllFilesImg
end repeat
delete char -1 of sAllFilesImg
answer "First file: " & line 1 of sAllFilesImg & cr & "Last file:" & line -1 of sAllFilesImg
end GetImagesFiles
load the image with the filename at the position where the user swiped.
Code: Select all
on showImg pNum -- pNum = the num of a line
get line pNum of sAllFilesImg
set the filename of img "MyImage" to (sCurfolder & "/" & it)
end showImg
Code: Select all
put the files into tList
split tList by cr
Code: Select all
get tList[3]
Code: Select all
get line 3 of tList