工作需要查看某工程下文件名相同的文件,遂写下此应用...
air提供了很多个文件系统操作控件,之前也没接触过air对目录和文件的操作,查了查api就coding了....
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" backgroundGradientColors="[0x000000,0x323232]">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FileEvent;
private var fileCollection:ArrayCollection=new ArrayCollection();
private var fileNameCollection:ArrayCollection=new ArrayCollection();
private var currentdir:File;
private var indexArray:Array;
[Bindable]
private var text:String="";
private function changeHandler():void
{
currentdir=tree.selectedItem as File;
}
private function output(dir:File):void
{
var contents:Array=dir.getDirectoryListing();
for each (var item:File in contents)
{
//目录
if (item.isDirectory)
{
output(item);
}
else //文件
{
fileCollection.addItem(item);
fileNameCollection.addItem(item.name);
}
}
}
//files had already stored in collection
private function print():void
{
indexArray=new Array();
for (var i=0; i < fileNameCollection.length; i++)
{
for (var j=i + 1; j < fileNameCollection.length; j++)
{
if (fileNameCollection[i] == fileNameCollection[j])
{
if (checkIndex(i))
{
indexArray.push(i);
text+=File(fileCollection.getItemAt(i)).nativePath + "\n";
}
if (checkIndex(j))
{
indexArray.push(j);
text+=File(fileCollection.getItemAt(j)).nativePath + "\n";
}
}
}
}
}
private function checkIndex(index:int):Boolean
{
for (var i in indexArray)
{
if (i == index)
{
return false;
}
}
return true;
}
private function clickHandler(event:MouseEvent):void
{
output(currentdir);
print();
}
]]>
</mx:Script>
<mx:FileSystemTree id="tree"
itemClick="changeHandler()"
width="300"
height="100"/>
<mx:TextArea width="300"
height="150"
text="{text}"/>
<mx:Button label="print"
click="clickHandler(event);"/>
</mx:WindowedApplication>
本文介绍了一个使用Adobe AIR开发的应用程序,该程序可以扫描指定目录及其子目录中的所有文件,并找出具有相同文件名的文件。通过遍历文件系统并将文件路径输出到文本区域,方便用户查看重复文件。

397

被折叠的 条评论
为什么被折叠?



