Restore original uppercase filenames after file upload

If you upload files via drag-and-drop using the Boomla toolchain, either via the IDE or your main site, your filenames will be converted to lowercase. That may be great for having nice URLs, not so great for programmers.

Here is an automated fix:

  1. Create a file anywhere on the website's filesystem,

  2. set it's type to sjs-4,

  3. set it's body to the code below,

  4. change /x at the top of the code to the subtree where you want to rename files, and

  5. visit it in your browser.

For example, rename /x to / to rename files everywhere in your website.

 

// Select another file to only renamed uploaded files under it
f = f.select('/x');
 
var renamed = '';
var failedToRename = '';
 
f.walk(function(fi) {
var origName = fi.title();
var name = fi.name();

if (origName === '') {
   return; // Not a regularly uploaded file, skip
}
if (name !== origName) {
try {
fi.rename(origName);
renamed += fi.path() + '\n';
}
catch(e) {
failedToRename += fi.path() + '\n';
}
}
});
 
var p = '';
p += '# RENAMED\n';
p += renamed;
p += '\n';
p += '\n';
p += '# FAILED TO RENAME\n';
p += failedToRename;
 
response.body(p);
response.attrStr('content-type', 'text/plain');