PDA

View Full Version : how to list all files and folders


Shadiq
01-08-2007, 04:19 AM
Hi all,

how to list all files and folders in a particular path.it has to list all subfolders and its content also.i did using "FLfile.listfolder" but i am not able to get subfolders content.could you please help me:confused:

jjbilly
01-08-2007, 11:23 AM
You need to call the same thing iteratively - take the folders in this list you get first, and look for their subfolders.

Narendrakumar
01-09-2007, 06:15 AM
Actually i made a code to get the same....

fl.outputPanel.clear()
var folderURI="file:///C|/Tool";
fileList =new Array()
paths="";

function listFile(paths){
files=[]
folds=[]
files=FLfile.listFolder(paths,"files");
for(i=0;i<files.length;i++){
fileList.push(paths+"/"+files[i]);
}
folds=FLfile.listFolder(paths,"directories");
for(j=0;j<folds.length;j++){

listFile(paths+"/"+folds[j])
}
}
listFile(folderURI);
fl.trace(String(fileList).split(",").join("\n"));

i tried for the following folder structure

Tool(Folder)
...A(file)
...F1(Folder)
......F1A(file)
...F2(Folder)
......F2A(file)

but i got only result for F1.

how can i resolve?

jjbilly
01-23-2007, 01:29 PM
Have you tried writing iterative functions?

This means: you write a function which takes the name of a folder as a parameter; it looks through that folder, and adds all the files it finds to your list of files. It looks through for folders, and for each of them, it calls itself (ie the same function), but now with the name of this new folder passed as the parameter. That way, you eventually end up with a list of all files, including those in sub folders.

Narendrakumar
01-24-2007, 03:13 AM
i did the recursive function.see the bold text

fl.outputPanel.clear()
var folderURI="file:///C|/Tool";
fileList =new Array()
paths="";

function listFile(paths){
files=[]
folds=[]
files=FLfile.listFolder(paths,"files");
for(i=0;i<files.length;i++){
fileList.push(paths+"/"+files[i]);
}
folds=FLfile.listFolder(paths,"directories");
for(j=0;j<folds.length;j++){

listFile(paths+"/"+folds[j])
}
}
listFile(folderURI);
fl.trace(String(fileList).split(",").join("\n"));

but not working for above folder structure...
please help me

darkzak
01-24-2007, 04:48 AM
You almost had it.


fl.outputPanel.clear()
var folderURI="file:///C|/tools/";
fileList =new Array()
paths="";

function listFile(paths){
var files=[]
var folds=[]
var files=FLfile.listFolder(paths,"files");

for(i=0;i<files.length;i++){
fileList.push(paths+files[i]);
}
var folds=FLfile.listFolder(paths,"directories");

for(var j=0;j<folds.length;j++){
listFile(paths+folds[j]+"/");

//make sure that this stops at a reasonable point.
if (fileList.length > 1000)
return;
}


}
listFile(folderURI);
fl.trace(String(fileList).split(",").join("\n"));

Narendrakumar
01-24-2007, 07:18 AM
Thanks a lot...:)

Shadiq
01-24-2007, 07:31 AM
Thanks

The problem in Narendrakumar script is var and not "/".

darkzak
01-24-2007, 12:53 PM
Yes, your right. I came back to this after several hours and forgot what I had changed. The variables in the recursion were getting overwritten which was causing the recursion to stop too soon. Adding var to the local variables made sure that the variables were in the functions scope not the global scope.

kifah
06-05-2007, 12:59 PM
Hello
i'm begginer in actionscript and i need this code , but when i put this code to my flash document i got NAN values in the "output"
what's the problem and how can i view my list file as string on the the scene
please reply me as fast as you can
THANKS...

jjbilly
06-06-2007, 08:48 AM
Hi Kifah,

Welcome to the forum.

This is a JSFL function rather than an ActionScript function. JSFL is the language for scripting the Flash application itself, for automating author-time tasks. You're (very) much more limited in what intercation you can do with the system in Flash itself.

What exactly are you trying to do?

kifah
06-06-2007, 01:50 PM
Thanks jjbilly

What I'm trying to do is to get files names from a specific folder(directory) and but them in a array as a string .
so later i can use the array to load these files just like photo loader

so can you help me in that ...
and if you have any librery JSFL that help me
please confirm me
and
Thanks in advance

jjbilly
06-06-2007, 04:31 PM
To be clear - do you want to do this just once, at the time you right the FLA (in which case you can do it with JSFL), or do you want to make the list when the user runs the SWF (in which case JSFL is not the answer, and Flash can't do it alone); and is the directory on a server, or on the client?

kifah
06-06-2007, 06:27 PM
actually i working in a small project in Adobe Flex and as you know the flex builder accept ActionScript 2.0 or 3.0 classes and accept JavaScript classes somehow .
anyway I need the Librery you talking about that allow me to list my files names from a specifec folder which it is not in the client so please tell me the way to do this even if without the librery of JSFL OK ...

thanks alot

jjbilly
06-08-2007, 01:54 PM
I'm not sure I can help you - I think you need to look at the server-side scripting board.

Apologies if I've got the wrong end of the stick...

dijeo
09-05-2007, 05:03 PM
I tried same codes but it's not working. When i test movie, nothing happend. In the Debug menu of the player there are two items called "List Object" and " List Variables". List object is empty.
List Variables is

"WIN 8,0,22,0"

"file:///C|/tools/"
] []



0
0


What is problem?

Note: Sorry for my English.