Ah, that’s the thing! “Actions” sounds good’n’all but … and didn’t you … we can’t let anybody loose with a “fully functional” live run to the RJM Programming web server with this renaming web application. We’ll just have to show you what the same codebase produces on our local MAMP (Mac) Apache/PHP/MySql web server in “fully functional” form.
Happily, our second draft of rename_to_aid_sorting.php, that changed this way, can be tried, by you, at this “forlornly functional, but still showing Analysis phase” (as we outlined with yesterday’s Renaming to Aid with Numerical File Sorts Primer Tutorial) live run link.
So after an initial phase of imagining how to resist bad usage thoughts, there were also more things to consider when allowing for real operating system rename commands (or mv on non-Windows operating systems), such as …
- error (and status) messaging … related to
- input file does not exist
- output file already exists
- rename fails
- (else mention if successful)
- individual checkboxes to allow for individual renamings (which happen at an HTML iframe “child” run of the same codebase PHP that performs an exec rename call from the (relevant) operating system (though we could have used PHP’s rename command to not have to differentiate via operating system, this way), the PHP’s way to tell happening via PHP_OS global)
- overall checkbox to allow for any non-checked individual checkboxes to be clicked in a batch … and if so …
- stagger the timing of it happening so user can read a status message between setTimeout controlled renamings
- give a report on the overall run at the end of this run
- show progress via cursor:progress; on the overall checkbox going back to cursor:pointer; at the finish
- control of the individual checkbox “checked” look happens at that HTML iframe’s onload event “Client Pre-Emptive Iframe” inspired logic
- after a successful rename ensure no bad repeated action, by use of [HTMLinputTextElement].readOnly=true on middle textbox and [HTMLinputCheckboxElement].style.display=’none’ on right hand side checkbox
- spaces in filenames requires double quoting delimitation
It’s amazing how much extra thought you need to put into procedural web applications like this, because the user needs follow up information in a real sense.
Did you know?
What is behind how PHP takes the input entries and obtains a set of file names (we refer to as “input” files above)? It’s done via one of our favourite PHP functions … (good ol’) …
foreach (glob($dprefix . $asteriskybit) as $filename) {
// process $filename here
}
Notice its abilities as far as wildcards go … * (for any number of character) and ? (for one character) and [0123456789] (we use in this project, for one counting number character).
Previous relevant Renaming to Aid with Numerical File Sorts Primer Tutorial is shown below.
It’s not just the operating systems that throw up issues regarding file names with numerical parts to them that when displayed get sorted alphabetically, but you’d like it either …
- numerically … or …
- a hybrid of numerically and alphabetically
We’re not there yet … but “are we there yet”, now? … but we’re starting down the road to this with some PHP we’re developing. This might be useful as a tool because sometimes with real work, you could be talking about hundreds of files needing renaming either to …
- suit some procedural (process) that is looking for the numbers to determine order, and yet uses defaulting file sorting algorithms … ie. what we are talking about today is a program to make it that both are satisfied, so long as the procedure doesn’t mind filenames being changed this way, to still work
- annoyance factor issues, the one that springs to mind for me being the assembly of some images that we use Mac OS X desktop application Preview to use to assemble into a PDF slideshow via being in the Mac OS X Finder and highlighting our files and running into the alphabetic/numerical sort conundrum … annoyance only? … by that I mean, you can fix this at Preview, so it rates as an “annoyance” only
What’s involved? Lots … think of this in terms of prefixing the correct number of “0”‘s (ie. zeroes) in the right place of the filename …
- the file extension … we decide not to cross across file extensions with our mini-renaming-rule sets
- the number of delimited sets before the period (ie. dot “.”) of the file extension … we decide not to cross across “file extension/number of delimited sets before the period”s with our mini-renaming-rule sets
- the delimiter itself before the period (and if none, call it the period) … we decide not to cross across “file extension/number of delimited sets before the period/delimiter”s with our mini-renaming-rule sets
- how many “delimited sets before the period” to apply the renaming logic attempts onto … we’ve decided just the first for now
- what about non-numerical and non-delimiter characters before the period … hand me the Bex, will you?!
Our first draft of rename_to_aid_sorting.php can be tried, by you, at this live run link.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.