{"id":37604,"date":"2018-04-23T03:02:47","date_gmt":"2018-04-22T17:02:47","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=37604"},"modified":"2018-04-24T08:51:19","modified_gmt":"2018-04-23T22:51:19","slug":"renaming-to-aid-with-numerical-file-sorts-actions-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/renaming-to-aid-with-numerical-file-sorts-actions-tutorial\/","title":{"rendered":"Renaming to Aid with Numerical File Sorts Actions Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Renaming to Aid with Numerical File Sorts Actions Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting_actions.jpg\" title=\"Renaming to Aid with Numerical File Sorts Actions Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Renaming to Aid with Numerical File Sorts Actions Tutorial<\/p><\/div>\n<p>Ah, that&#8217;s the thing!  &#8220;Actions&#8221; sounds good&#8217;n&#8217;all but <font size=1>&#8230; and didn&#8217;t you &#8230;<\/font> we can&#8217;t let anybody loose with a &#8220;fully functional&#8221; live run to the RJM Programming web server with this renaming web application.  We&#8217;ll just have to show you what the same codebase produces on our local <a target=_blank title='MAMP Mac Apache\/PHP\/MySql local web server' href='http:\/\/www.mamp.info\/'>MAMP<\/a> (Mac) Apache\/PHP\/MySql web server in &#8220;fully functional&#8221; form.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/idzkZ5x1DEc\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/p>\n<p>Happily, our second draft of <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php-GETME\">rename_to_aid_sorting.php<\/a>, <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php-GETME\">that changed this way<\/a>, can be tried, by you, at this &#8220;forlornly functional, but still showing Analysis phase&#8221; (as we outlined with yesterday&#8217;s <a title='Renaming to Aid with Numerical File Sorts Primer Tutorial' href='#ranfspt'>Renaming to Aid with Numerical File Sorts Primer Tutorial<\/a>) <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php\" title=\"Click picture\">live run<\/a> link.<\/p>\n<p>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 <i>rename<\/i> commands (or <i>mv<\/i> on non-Windows operating systems), such as &#8230;<\/p>\n<ul>\n<li>error (and status) messaging &#8230; related to\n<ol>\n<li>input file does not exist<\/li>\n<li>output file already exists<\/li>\n<li>rename fails<\/li>\n<li>(else mention if successful)<\/li>\n<\/ol>\n<\/li>\n<li>individual checkboxes to allow for individual renamings (which happen at an HTML iframe &#8220;child&#8221; run of the same codebase PHP that performs an <i>exec<\/i> rename call from the (relevant) operating system (though we could have used PHP&#8217;s <a target=_blank title='PHP rename information' href='http:\/\/php.net\/manual\/en\/function.rename.php'>rename<\/a> command to not have to differentiate via operating system, this way), the PHP&#8217;s way to tell happening via PHP_OS global)<\/li>\n<li>overall checkbox to allow for any non-checked individual checkboxes to be clicked in a batch &#8230; and if so &#8230;\n<ol>\n<li>stagger the timing of it happening so user can read a status message between <a target=_blank title='Javascript setTimeout method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_settimeout.asp'>setTimeout<\/a> controlled renamings<\/li>\n<li>give a report on the overall run at the end of this run<\/li>\n<li>show progress via <i>cursor:progress;<\/i> on the overall checkbox going back to <i>cursor:pointer;<\/i> at the finish<\/li>\n<\/ol>\n<\/li>\n<li>control of the individual checkbox &#8220;checked&#8221; look happens at that HTML iframe&#8217;s <i>onload<\/i> event &#8220;Client Pre-Emptive Iframe&#8221; inspired logic<\/li>\n<li>after a successful rename ensure no bad repeated action, by use of [HTMLinputTextElement].readOnly=true on middle textbox and [HTMLinputCheckboxElement].style.display=&#8217;none&#8217; on right hand side checkbox<\/li>\n<li>spaces in filenames requires double quoting delimitation<\/li>\n<\/ul>\n<p>It&#8217;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.<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>What is behind how PHP takes the input entries and obtains a set of file names (we refer to as &#8220;input&#8221; files above)?   It&#8217;s done via one of our favourite PHP functions &#8230; (good ol&#8217;) &#8230;<\/p>\n<p><code><br \/>\nforeach (<a target=_blank title='PHP glob() method information' href='http:\/\/php.net\/manual\/en\/function.glob.php'>glob<\/a>($dprefix . $asteriskybit) as $filename) {<br \/>\n   \/\/ process $filename here<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Notice its abilities as far as <a target=_blank title='Useful link, thanks' href='http:\/\/teaching.idallen.com\/cst8207\/15w\/notes\/190_glob_patterns.html'>wildcards<\/a> go &#8230; * (for any number of character)  and ? (for one character) and [0123456789] (we use in this project, for one counting number character).<\/p>\n<hr>\n<p id='ranfspt'>Previous relevant <a target=_blank title='Renaming to Aid with Numerical File Sorts Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/renaming-to-aid-with-numerical-file-sorts-primer-tutorial\/'>Renaming to Aid with Numerical File Sorts Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Renaming to Aid with Numerical File Sorts Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.jpg\" title=\"Renaming to Aid with Numerical File Sorts Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Renaming to Aid with Numerical File Sorts Primer Tutorial<\/p><\/div>\n<p>It&#8217;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&#8217;d like it either &#8230;<\/p>\n<ul>\n<li>numerically &#8230; or &#8230;<\/li>\n<li>a hybrid of numerically and alphabetically<\/li>\n<\/ul>\n<p>We&#8217;re not there yet <font size=1>&#8230; but &#8220;are we there yet&#8221;, now? &#8230;<\/font> but we&#8217;re starting down the road to this with some PHP we&#8217;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 &#8230;<\/p>\n<ul>\n<li>suit some procedural (process) that is looking for the numbers to determine order, and yet uses defaulting file sorting algorithms &#8230; ie. what we are talking about today is a program to make it that both are satisfied, so long as the procedure doesn&#8217;t mind filenames being changed this way, to still work<\/li>\n<li>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 &#8230; annoyance only? &#8230; by that I mean, you can fix this at Preview, so it rates as an &#8220;annoyance&#8221; only<\/li>\n<\/ul>\n<p>What&#8217;s involved?  Lots &#8230; think of this in terms of prefixing the correct number of &#8220;0&#8221;&#8216;s (ie. zeroes) in the right place of the filename &#8230;<\/p>\n<ul>\n<li>the file extension &#8230; we decide not to cross across file extensions with our mini-renaming-rule sets<\/li>\n<li>the number of delimited sets before the period (ie. dot &#8220;.&#8221;) of the file extension &#8230; we decide not to cross across &#8220;file extension\/number of delimited sets before the period&#8221;s with our mini-renaming-rule sets<\/li>\n<li>the delimiter itself before the period (and if none, call it the period) &#8230; we decide not to cross across &#8220;file extension\/number of delimited sets before the period\/delimiter&#8221;s with our mini-renaming-rule sets<\/li>\n<li>how many &#8220;delimited sets before the period&#8221; to apply the renaming logic attempts onto &#8230; we&#8217;ve decided just the first for now<\/li>\n<li>what about non-numerical and non-delimiter characters before the period &#8230; hand me the <a target=_blank title='Take a Bex ... and ...' href='https:\/\/www.youtube.com\/watch?v=BF6ffbz70SY'>Bex<\/a>, will you?!<\/li>\n<\/ul>\n<p>Our first draft of <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php_GETME\">rename_to_aid_sorting.php<\/a> can be tried, by you, at this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting.php\" title=\"Click picture\">live run<\/a> link.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d37583' onclick='var dv=document.getElementById(\"d37583\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/file\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d37583' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d37604' onclick='var dv=document.getElementById(\"d37604\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/checkbox\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d37604' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Ah, that&#8217;s the thing! &#8220;Actions&#8221; sounds good&#8217;n&#8217;all but &#8230; and didn&#8217;t you &#8230; we can&#8217;t let anybody loose with a &#8220;fully functional&#8221; live run to the RJM Programming web server with this renaming web application. We&#8217;ll just have to show &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/renaming-to-aid-with-numerical-file-sorts-actions-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,29,37],"tags":[2535,202,2276,2147,327,336,405,1797,418,450,1615,587,744,1520,885,932,997,1872,1173,1675,1319,1411],"class_list":["post-37604","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-operating-system","category-tutorials","tag-alphabetic","tag-checkbox","tag-delimitation","tag-delimiter","tag-did-you-know","tag-directory","tag-exec","tag-extension","tag-file","tag-folder","tag-glob","tag-iframe","tag-mamp","tag-numerical","tag-operating-system-2","tag-php","tag-programming","tag-rename","tag-sort","tag-textbox","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/37604"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=37604"}],"version-history":[{"count":12,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/37604\/revisions"}],"predecessor-version":[{"id":37643,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/37604\/revisions\/37643"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=37604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=37604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=37604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}