This depends on the OS and / or the programming / scripting language you
know to operate it. I had written a tiny C# program to browse a given folder
for the files of a given type and generate an AS file with embeds, but, I'm
sure you can do the same with any language that can access to the file
system and process strings, even AIR can do that.
If you're interested in what I did - here it is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ResourceBatchProcessor
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml;
namespace ResourceBatchProcessor
{
class MXMLGenerator
{
public static string templateStart =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<fl:Sprite
xmlns:mx=""http://www.adobe.com/2006/mxml""
xmlns:fl=""flash.display.*""
xmlns:rs=""org.wvxvws.resources.*""
>";
public static string embed =
@" <rs:Resource embed=""@Embed(source='%path%')""/>
";
public static string templateEnd = "</fl:Sprite>";
public static Regex nonAlphaNum = new Regex(@"\W",
RegexOptions.Compiled);
public static void ProcessDirectory(string path)
{
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files = di.GetFiles("*.png");
string filePath;
string resultFileName = di.Parent.FullName + @"\" +
nonAlphaNum.Replace(di.Name, "_") + ".mxml";
string resultFile = (string)templateStart.Clone();
foreach (FileInfo fi in files)
{
filePath = ((string)embed.Clone()).Replace("%path%",
fi.FullName);
resultFile += filePath;
}
resultFile += templateEnd;
XmlTextWriter textWriter = new XmlTextWriter(resultFileName,
Encoding.UTF8);
textWriter.WriteRaw(resultFile);
textWriter.Close();
}
public static void ProcessDirectory(string[] path)
{
//DirectoryInfo[] di = new DirectoryInfo[path.Length];
//int i = 0;
foreach (string pt in path)
{
ProcessDirectory(pt);
//di.SetValue(new DirectoryInfo(pt), i);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ResourceBatchProcessor
{
public partial class Form1 : Form
{
private bool multipleSelected = false;
public Form1()
{
InitializeComponent();
this.buttonCreateMXML.Enabled = false;
this.buttonSelectFolder.Click += new
EventHandler(buttonSelectFolder_Click);
this.buttonCreateMXML.Click += new
EventHandler(buttonCreateMXML_Click);
this.buttonSelectAllFolders.Click += new
EventHandler(buttonSelectAllFolders_Click);
this.textSelectedFolder.TextChanged += new
EventHandler(textSelectedFolder_TextChanged);
this.Resize += new EventHandler(Form1_Resize);
}
void buttonSelectAllFolders_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
this.textSelectedFolder.Text = dialog.SelectedPath;
}
this.multipleSelected = true;
}
void Form1_Resize(object sender, EventArgs e)
{
this.buttonCreateMXML.Width = this.Width - 30;
this.buttonSelectFolder.Width = this.Width - 30;
this.textSelectedFolder.Width = this.Width - 30;
this.buttonSelectAllFolders.Width = this.Width - 30;
this.label2.Width = this.Width;
}
void textSelectedFolder_TextChanged(object sender, EventArgs e)
{
if (this.textSelectedFolder.Text == "")
{
this.buttonCreateMXML.Enabled = false;
}
else
{
this.buttonCreateMXML.Enabled = true;
}
}
private void buttonCreateMXML_Click(object sender, EventArgs e)
{
if (this.textSelectedFolder.Text == "") return;
if (this.multipleSelected)
{
DirectoryInfo di = new
DirectoryInfo(this.textSelectedFolder.Text);
DirectoryInfo[] dil = di.GetDirectories();
string[] paths = new string[dil.Length];
int i = 0;
foreach (DirectoryInfo d in dil)
{
paths.SetValue(d.FullName, i);
i++;
}
MXMLGenerator.ProcessDirectory(paths);
}
else
{
MXMLGenerator.ProcessDirectory(this.textSelectedFolder.Text);
}
}
private void buttonSelectFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
this.textSelectedFolder.Text = dialog.SelectedPath;
}
this.multipleSelected = false;
}
}
}
+ There was a designer generated code for the form with 2 text inputs and 2
buttons, but I won't post it because it's to long, and you'll get it the
same anyway.
Best.
Oleg