1 Reply Latest reply on Jan 25, 2011 8:38 AM by UbuntuPenguin

    Files, directories and subdirectories count

    Pisti123

      Hello,

       

      I'm currently building a small AIR application via Flash Builder 4 (FLEX 4) that will count the number of files (EVERY type of file)

      in a certain directory (choosen by the user) the problem gets when I have subdirectories,

      tried recursive (which is basicly the only solution) and got stuck and confused with myself, can anyone help a brother out here?

       

       

                  private var directory:File = File.documentsDirectory;
                  [Bindable]
                  private var count:int = 0;
                 
                  public function browseForDirectory():void
                  {
                      directory.browseForDirectory("Select Directory");
                      directory.addEventListener(Event.SELECT, directorySelected);
                  }
                 
                  public function directorySelected(event:Event):void
                  {
                      directory = event.target as File;
                      var files:Array = directory.getDirectoryListing();
                      for(var i:int = 0; i < files.length; i++)
                      {
                          myPath.text = directory.nativePath;
                      }
                  }
                  public function countFiles():void
                  {
                      var files:Array = directory.getDirectoryListing();
                      for (var i:int = 0; i < files.length ; i++)
                      {
                          count++;
                          if (files[i].isDirectory)
                          {
                              count += countFiles();
                          }
                      }
                      myResult.text = count.toString();
                  }

       

       

      Hoping for a quick response, Thanks!