Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-17-2004, 03:04 AM   #1
Hoogs
Dimmus Wittus
 
Hoogs's Avatar
 
Join Date: May 2004
Location: Melbourne
Posts: 52
Default List file names

I have php creating text files in a specified folder for me but now I want to be able to list all the file names in the folder.

Ultimately I would like to use a search to retrieve file names.
I could do this in flash if I can get the file names into an array but would love to know if there is a better way of doing this.

Are there any tutorials dealing with this?

Thanks.
Hoogs is offline   Reply With Quote
Old 12-17-2004, 03:18 AM   #2
petefs
Fried Onions
 
petefs's Avatar
 
Join Date: Apr 2004
Location: Chicago, IL
Posts: 1,328
Send a message via AIM to petefs Send a message via MSN to petefs Send a message via Yahoo to petefs
Default

PHP Code:
$files = array();
$handle opendir("directory");
while(
$file == readdir($handle) if($files != "." && $files != ".."$files[] = $file;
closedir($handle);
echo 
"&files=" implode("|"$files); 
when that string variable 'files' is loaded into flash, use Array.split() to convert it into an array. i.e.
var file_array:Array = files.split("|");

that should handle the getting all the files into an array for ya ^_^
petefs is offline   Reply With Quote
Old 12-17-2004, 03:41 AM   #3
Hoogs
Dimmus Wittus
 
Hoogs's Avatar
 
Join Date: May 2004
Location: Melbourne
Posts: 52
Default

Nice. Thanks for that.

If you have time, would you be able to explain the
Quote:
while($file == readdir($handle) if($files != "." && $files != "..") $files[] = $file;
line?

Thanks again.

Last edited by Hoogs; 12-17-2004 at 03:56 AM.
Hoogs is offline   Reply With Quote
Old 12-17-2004, 06:13 AM   #4
petefs
Fried Onions
 
petefs's Avatar
 
Join Date: Apr 2004
Location: Chicago, IL
Posts: 1,328
Send a message via AIM to petefs Send a message via MSN to petefs Send a message via Yahoo to petefs
Default

well, I'm lazy, and I made a bunch of typoes, but that should probably be written as
PHP Code:
while (false !== ($file readdir($handle))) {
    if(
$file != "." && $file != "..") {
        
$files[] = $file;
    }

notice the corrections, it's important :b

anyway, here's the breakdown : )

1: while (false !== ($file = readdir($handle)))
readdir($handle) returns the next file in the directory -- when there are none left, it evaluates to false and ends the while loop.

2: if($file != "." && $file != "..")
we're just checking here to make sure that the $file isn't . or .. which are both present in every folder and mean 'this folder' and 'parent folder'

3: $files[] = $file
throw the file into the array : )

If you have other directories in that directory it will cause problems -- you'll have to check if it's a directory using is_dir. If you're just looking for a certain kind of file, i.e. text files, replace the if conditional with this:

if (strtolower(substr($file, -4)) == ".txt")

that should hopefully take care of things for you ^_^
petefs is offline   Reply With Quote
Old 12-21-2004, 10:11 PM   #5
Hoogs
Dimmus Wittus
 
Hoogs's Avatar
 
Join Date: May 2004
Location: Melbourne
Posts: 52
Default

Above and beyond the call of duty.

Thanks a ridiculously large amount.
Hoogs is offline   Reply With Quote
Old 12-21-2004, 11:10 PM   #6
petefs
Fried Onions
 
petefs's Avatar
 
Join Date: Apr 2004
Location: Chicago, IL
Posts: 1,328
Send a message via AIM to petefs Send a message via MSN to petefs Send a message via Yahoo to petefs
Default

Too much is always better than not enough!

No problem ^^
petefs is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:43 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.