I am trying to generate XML of a user selected folder and inner folders along with the files recursively. Structure of the XML generated should be as the user selected folder.
I am able to list all the folders and files in the selected folder. I am unable to find a way to generate the same structure, I am unable to think of a way to replicate the depth of folder in XML. Any ideas to find solutions??
<?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](http://ns.adobe.com/flex/spark)"
xmlns:mx="library://[ns.adobe.com/flex/mx](http://ns.adobe.com/flex/mx)" creationComplete="init(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var file:File;
[Bindable]
private var fileName:String = "";
private function init(event:Event):void{
file = new File();
file.addEventListener(Event.SELECT, selectedFolderHandler, false, 0, true);
}
private function opebFolderHandler(event:MouseEvent):void{
file.browseForDirectory("Please select a folder ");
}
private function selectedFolderHandler(event:Event):void{
filePath.text = File(event.currentTarget).nativePath;
}
private function xmlConversionHandler(event:MouseEvent):void{
GetAllFilesFromDir(file);
}
public function GetAllFilesFromDir(folder:File):void
{
for each(var lstFile:File in folder.getDirectoryListing()){
if(lstFile.isDirectory){
GetAllFilesFromDir(lstFile);
}else{
trace(lstFile.nativePath);
}
}
}
]]>
</fx:Script>
<s:VGroup>
<mx:TextInput id="filePath" />
<mx:Button id="pathToFolder" label="browse to folder" click="opebFolderHandler(event)" />
<mx:Button id="listFiles" label="Make XML" click="xmlConversionHandler(event)" />
</s:VGroup>
</s:WindowedApplication>