Dir2xml

This is a little tool I build with the help of Screenweaver.
A dir(ectory) 2 XML tool.

I was looking for a program that could create an XML file from a directory. I found some programs that could help me with this (commandline, Printfolder, Dirhtml) but none of them creates an XML at once. So one evening I sat down, and made this in a couple of hours.

Because this is a custom solution to a specific problem, not everybody will be able to use this. I'm open to suggestions though, so drop me a line.

Dir2xml v1.0

dir2xml

PC and Apple

Sadly enough Screenweaver can't export to Apple (yet).
So Dir2xml will (for now) only work on a pc.

Download

You can download the EXE, SWF and FLA in a ZIP

Get your stuff here: dir2xml_060520.zip

update: new version

Licensing

Code

The code is embedded in the fla so I'll show the code here.

////////////////////////////////////////////////////
// choose a folder to create xml from
/////////////////////////////////////////////////////
this.folder_txt.text = "";
this.button_btn.btn_txt.text = "Choose folder";
this.button_btn.onRelease = function() {
trace("- choose folder -");
swSystem.Dialogs.BrowseForFolder("Please choose a folder...", _root.onBrowseFolder, this);
};
// check if a folder is chosen
function onBrowseFolder(success, folder) {
if (success) {
_root.chosenFolder = folder;
_root.folder_txt.text = _root.chosenFolder;
_root.save_txt.text = _root.chosenFolder + "dir2xml.xml";
_root.file = _root.chosenFolder + "dir2xml.xml";
swDebug.trace("_root.chosenFolder: " + _root.chosenFolder);
swFile.listFolder(_root.chosenFolder, "file", "", 0, listFolder_callback, this);
} else {
swDebug.trace("- cancel browsing for folder -");
}
}
// list folder for files
// escape 250 if necessary
function listFolder_callback(success, index, data) {
if (data.length < 250) {
for (i in data) {
swDebug.trace(data[i]);
}
_root.createXml(data);
swDebug.trace(" - finished loading data from folder - ");
} else {
swFile.listFolder(_root.chosenFolder, "file", "", index, listFolder_callback, this);
}
}
/////////////////////////////////////////////////////
// create xml
/////////////////////////////////////////////////////
function createXml(data:Array):Void {
swDebug.trace("createXml - " + data.length);
var writeXml:String = "";
writeXml += "n";
writeXml += "n";
for (var i = 0; i < data.length; i++) {
writeXml += "t" + data[i] + "n";
}
writeXml += "n";
_root.writeXml = writeXml;
}
//////////////////////////////////////////////
// save xml file in
//////////////////////////////////////////////
this.save_txt.text = "";
this.save_btn.btn_txt.text = "Save as";
this.save_btn.onRelease = function() {
trace("- Save as -");
_root.SaveFileIn();
};
// where
function SaveFileIn() {
swSystem.Dialogs.BrowseForFile_Save("dir2xml.xml", ["XML Files", "*.xml", "All Files", "*.*"], _root.saveFileIn, "Save File", ".xml", _root.onSaveFileIn);
}

// real save
function onSaveFileIn(success, file) {
if (success) {
swDebug.trace("User selected: " + file);
_root.file = file;
_root.save_txt.text = _root.file;
} else {
swDebug.trace("- User did not save to file! -");
}
}
// export
this.export_btn.btn_txt.text = "Export XML";
this.export_btn.onRelease = function() {
trace("- Export XML -");
startSaving();
};
function startSaving() {
swFile.saveString(_root.file, _root.writeXml, false, _root.onSaveDocument);
}
// check
function onSaveDocument(succes) {
if (succes) {
swDebug.trace("- User saved -");
trace(_root.checkBox_mc.checked);
swDebug.trace(">> " + _root.checkBox_mc.checked);
if (_root.checkBox_mc.checked) {
swSystem.shellOpenDocument(_root.file);
}
} else {
swDebug.trace("- something went wrong -");
}
}
//
this.checkBox_mc.checkbox_txt.text = "Open file";

Wish list and To-do

Features:

  • Recursive through all folders
  • Recursive through xx number of folders
  • Filters for JPG, GIF, Flash 7 images, Flash 8 images
  • Hidden data in XML (kB, createDate, width, height, URL)
  • …..

Do you know some features that would make this program better, let me know and drop a line.