as3 递归 遍历文件夹

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">
 
 <fx:Script>
  <![CDATA[
   
   private var FilrUrlArr:Array = new Array();
   

   

   protected function button1_clickHandler(event:MouseEvent):void
   {
    
    GetFiles("E:\\myWork");
    for each (var obj:Object in FilrUrlArr)
    {
     trace(obj.toString());
    }
   
   }
   
   public function GetFiles(strPath:String):void
   {
    //获取指定路径下的所有文件名
    var directory:File = new File(strPath);
    var contents:Array = directory.getDirectoryListing();
    for (var i:uint = 0; i < contents.length; i++)
    {
     trace(contents[i].name, contents[i].size);
     var file:File = contents[i] as File;
     
     if(file.isDirectory){
      
      GetFiles(file.nativePath);
      
     }else{
      
      
      FilrUrlArr.push(file.nativePath + "==" + file.extension);
      
     }
     

    }
   }
   
   
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <s:Button x="44" y="104" label="按钮" click="button1_clickHandler(event)"/>
</s:WindowedApplication>

你可能感兴趣的:(as3 递归 遍历文件夹)