# Generate XML of selected folders and files

**URL:** <https://forum.kirupa.com/t/generate-xml-of-selected-folders-and-files/319656>\
**Category:** flash\
**Created:** [February 28, 2011, 4:10pm UTC](https://forum.kirupa.com/t/generate-xml-of-selected-folders-and-files/319656 "2011-02-28T16:10:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaji](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@shaji](https://forum.kirupa.com/u/shaji)\
**Post date:** [February 28, 2011, 4:10pm UTC](https://forum.kirupa.com/t/generate-xml-of-selected-folders-and-files/319656/1 "2011-02-28T16:10:27Z")

</div>

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??

```auto

<?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>

```
