Tag Archives: Appcelerator

Batch File Actions – a sample Appcelerator/Titanium app with source code

Warning: Nerd Alert!

I’ve been playing around with the Appcelerator/Titanium development platform lately, finally developing an app I’ve wanted to write for years: Batch File Actions. (I think in a previous post I called it Batch Rename.) Appcelerator is a sytem similar to Adobe AIR to allow people to use web technologies like HTML, CSS JavaScript and PHP to build applications that are packaged with the Appcelerator runtime which works on Linux, Windows or Mac, and with a few tweaks, can work on iPhone/iPad, Android and BlackBerry support coming soon.

The app I’m putting together is a tool that allows you to parse through folders and files and commit an action (move, delete, copy, rename) on any file and/or folder that matches certain criteria. At this point, the app is functional and seems to work just fine. However, I still haven’t added all the features I need to ensure both safety and usability. For example, you can enter a regular expression (regex) into the “name contains” field to place extremely complex rules on which files to select. The only issue is that only my fellow coders will even know what a regular expression is. I want to add a utility to build those regexes based on choices and selection boxes and whatnot, but that’ll be a bit of an undertaking.

I also need to add a “parse recursively” checkbox so users can pound through sub-folders and add an unzip option since I think I’ve actually been in situations where I wanted to parse through folders and programatically unzip multiple zip files…

…a little bug testing would be nice too considering that a few mistakes in my code could potentially do serious damage to someone’s data.

So here is the source code that I have written so far. You will of course, need to get the Appcelerator development environment and copy the files into your app’s directory in order to actually compile the app.

And here is the actual Batch File Actions app. I hesitate to actually put up this link because I fear someone will trust me too much. My point of this is more to provide example source code for others getting started in Appcelerator. So please DO NOT actually use this unless you are certain you have everything backed up on a drive not connected to your computer. I’m not aware of any serious issues, but I do not have any kind of Quality Assurance team in my apartment.

One funny bug I did find happened when I selected a folder, left the ‘name contains’ field blank so it caught all files, then I set it to copy those files and folders into a sub-folder of the folder I had selected. This appeared to copy all the files recursively into the folder an infinite number of times. I clicked on each subfolder and on each level there was just another copy of all the files and folders. I kept clicking and clicking until I had gone down 20 or 30 levels and still couldn’t find an end to the copied files. How that didn’t cause anything to crash, I don’t know. It must have given up after 256 levels or something.

Oh, yeah, the other cool thing about this app is that it prints all your options out in a JSON string (originally I wanted to create my own SQL-esque language, but I think JSON makes more sense). Right now this is kind of useless, but eventually I want to allow people to save the string to a file so it can be re-run again simply by opening the file or pasting the string into the textfield. Unfortunately, that stupid regex escape character (\) gets converted whenever I try to print a regex to the textfield.

Anyway, hope someone gets some use out of this–or at least takes my code for use in something else. Whatever you do, don’t accidentally delete all your porn.