• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

getDirectoryListing slooooooowwww

Guest
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

Hey guys

Just wondering if there is a faster way of obtaining a file name list of a directory's contents than getDirectoryListing?

It seems to take FOREVER to load a dir list into an array.

My end objective is to populate a .txt file with the names of files in a directory.

Any tips would be appreciated.

Cheers

Shaun

TOPICS
ActionScript

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 24, 2012 Jan 24, 2012

the code i sent breaks your for-loop into manageable chunks.  i think you can safely use chunks greater than 100 loops.  i have a parameter you can use.

and, you can use getDirectoryListingAync() to use an asynchronous method that won't freeze your computer while the directory is being selected.

Votes

Translate

Translate
Guest
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

How many files are in the folder? How long is forever?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

5000 files takes about 7 seconds.  50 000 files takes 90.  The app I'm working on will be used on dirs containing up to 100 000 files.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

you must have a major slow computer or you're still using a trace() function when you should not be using a trace.  when i tested it took less than 0.3 seconds to load and parse those 5000 file names.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

Really?!?!?  Hmmm.  It's an i5 lappy, so isn't super fast but not super slow either.

What's happening is the getDirectoryListing is taking ages, but once the file names are loaded into the array the, parsing happens in under a second.

What speed is your computer?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

i tested on 2 i7 pcs but the older one is vista so it's not that new and neither has an ss hd.

are you using a trace() function anywhere to list a lot of data?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

No trace.  I was using an external USB drive, and tested it on a local drive, which is faster, but still slow - it takes 4 seconds to load the files, then 2.5 seconds to parse, then 1.5 to display the results in the text field.

So a 50 000 file job will take about 1.5 mins. 

It's not so much the time that worries me, but not being able to update the screen with a progress meter while getDirectoryListing is loading file names makes it look like it's hung.  It's fine once the parsing starts, as I have your code showing progress.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

during the load just display a static:

loading...

then you can update with the code i sent.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

So your code just kicks in once the parsing starts?

Does Adobe not have any sort of progress code for getDirectoryListing?

Thanks mate

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2012 Jan 24, 2012

Copy link to clipboard

Copied

the code i sent breaks your for-loop into manageable chunks.  i think you can safely use chunks greater than 100 loops.  i have a parameter you can use.

and, you can use getDirectoryListingAync() to use an asynchronous method that won't freeze your computer while the directory is being selected.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 26, 2012 Jan 26, 2012

Copy link to clipboard

Copied

Thanks for the code kglad - I just got around to fully implementing it today.

I have adapted it to use getDirectoryListingAync(); - it allows me to bring up a MC with a message saying 'reading files...' , and I tried dsiplaying a flashing MC underneath it, but it seems Flash can't update the UI until the files have been read:

function selectDir(event:Event):void {       

               

        d1.browseForDirectory("Select your files directory"); //Open directory browser

        d1.addEventListener(Event.SELECT, importFiles); //When directory is selected, run importFiles function

    }

   

   

    function importFiles(event:Event):void {

       

          d1.getDirectoryListingAsync();

          messageMC.visible = true;

          animatedMC.visible = true;    

          d1.addEventListener(FileListEvent.DIRECTORY_LISTING, getContents);

     }

the UI is able to be updated in the getContents function, but not while getDirectoryListingAsync() is processing.

I think this is just a limitation of Flash we have to accept until they introduce multi threading.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2012 Jan 26, 2012

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines