Counting Files In A folder

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Counting Files In A folder

Post by warrenk » Sun Sep 21, 2008 5:43 am

I am trying to count the number of files in a selected folder and place it in a text box. I am a newbie so I do apologize if this is something very basic. I have searched the documentation and couldn't find any help for this.

Thanks for any help!
Warren

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Sun Sep 21, 2008 8:14 am

If these are in the Media version, then check out the following in the documents:

defaultfolder
files

defaultfolder will allow you to select the directory you need and you can use that also when using files to get a list of all the files in the directory you set with defaultfolder.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Sep 21, 2008 12:48 pm

hi warrenk,

try this, it should get you started

Code: Select all

on mouseUp pMouseBtnNo
    answer folder "please choose folder to get the files of"
    if it is empty then exit mouseUp
    put it into tFolderToSearch
    put the defaultfolder into tOldDefaultFolder -- to restore it later
    set the defaultfolder to tFolderToSearch
    put the files into tAllFiles -- gives you all the files of the folder
    -- you may want to filter the files for the type you want; look up filter with or filter without
    --filter tAllFiles without ".*"  -- on a mac there are invisible files that start with a dot
    --filter tAllFiles with "*.rev" -- to just get rev stacks
    --filter tAllFiles with "*.pdf" -- to just get pdfs
    set the defaultfolder to tOldDefaultFolder -- restore the default folder, not necessary but nice
    put 0 into tSoMany -- just in case there are none
    put the number of lines of tAllFiles into tSoMany
    put "there are " & tSoMany & " files" & return & "these are the files: " & return & tAllFiles
end mouseUp
regards
bernd

warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Post by warrenk » Sun Sep 21, 2008 4:54 pm

Thanks Bernd...thats exactly what I was looking for!

Much appreciately!!!! :D
Warren

Post Reply