{"id":42181,"date":"2018-12-06T03:01:29","date_gmt":"2018-12-05T17:01:29","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=42181"},"modified":"2018-12-05T21:17:53","modified_gmt":"2018-12-05T11:17:53","slug":"renaming-scenario-in-single-folder-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/renaming-scenario-in-single-folder-primer-tutorial\/","title":{"rendered":"Renaming Scenario in Single Folder Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/renameidea.jpg\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Renaming Scenario in Single Folder Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/renameidea.jpg\" title=\"Renaming Scenario in Single Folder Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Renaming Scenario in Single Folder Primer Tutorial<\/p><\/div>\n<p>The renaming of files in any automated or bulk or batch line of thinking &#8230;<\/p>\n<ul>\n<li>is most often tackled with server applications, not web applications &#8230; due to security risks &#8230; true with today&#8217;s work below too with the difference that today&#8217;s work can be run with a local (Apache\/PHP\/MySql) web server (in PHP) like <a target=_blank title='MAMP' href='https:\/\/mamp.info'>MAMP<\/a><\/li>\n<li>is complex to totally genericize totally, but various rename patterns can be &#8230; one such is presented today<\/li>\n<li>ideally can be previewed ahead of <a target=_blank title='PHP rename' href='http:\/\/php.net\/manual\/en\/function.rename.php'>doing<\/a>, in some way shape or form<\/li>\n<\/ul>\n<p> &#8230; versus the time saved of long unwieldy one-file-at-a-time command line commands.<\/p>\n<p>Today&#8217;s PHP renaming scenario started with a very specific requirement scenario, and we genericized because we thought it may suit a requirement of yours.  We break a file rename run of interest into &#8230;<\/p>\n<table>\n<tr>\n<th>Path<\/th>\n<th>Prefix &#8230; to &#8230;<br \/>New Prefix<\/th>\n<th>Stays<\/th>\n<th>Goes<br \/>(in terms of<br \/> its length)<\/th>\n<th>Extension<br \/>Preview Only?<\/th>\n<\/tr>\n<tr>\n<td><input style='width:20px;' name=path type='text' value='.\/' placeholder='.\/'><\/input><\/td>\n<td><input style='width:120px;' name=prefix type='text' value='act-' placeholder='act-'><\/input><br \/> &#8230; to &#8230; <input style='width:160px;' name=newprefix type='text' value='ACT~AUS~NSW~Y.' placeholder='ACT~AUS~NSW~Y.'><\/input><\/td>\n<td><input style='width:80px;' id=stays type='text' value='1989-76' placeholder='1989-76'><\/input><\/td>\n<td><input style='width:120px;' name=goes type='text' value='-2017-07-01' placeholder='-2017-07-01'><\/input><\/td>\n<td><input style='width:40px;' name=extension type='text' value='.xml' placeholder='.xml'><\/input><br \/>Preview Only? <input name=preview type=checkbox><\/input><\/td>\n<\/tr>\n<\/table>\n<p> &#8230; that the user interaction with, results in HTML form navigation back to the same PHP (as a child within an HTML iframe element placed below), that represents that <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/renameidea.jpg\" title=\"Click picture\">Rename Run Report<\/a>.<\/p>\n<p>This second generic draft of <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/renameidea.php-GETME\">renameidea.php<\/a> became the way it is from a first (very specific) draft <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/renameidea.php_GETME\">renameidea.php<\/a> in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/renameidea.php-GETME\">this way<\/a>.<\/p>\n<p>Given you&#8217;ve reached here, you may well want to read about another Rename themed blog posting thread at <a title='Renaming to Aid with Numerical File Sorts Command Line and Curl Tutorial' href='#ranfsclct'>Renaming to Aid with Numerical File Sorts Command Line and Curl Tutorial<\/a> as shown below.<\/p>\n<hr>\n<p id='ranfsclct'>Previous relevant <a target=_blank title='Renaming to Aid with Numerical File Sorts Command Line and Curl Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/renaming-to-aid-with-numerical-file-sorts-command-line-and-curl-tutorial\/'>Renaming to Aid with Numerical File Sorts Command Line and Curl 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 Command Line and Curl Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rename_to_aid_sorting_actions_curl.jpg\" title=\"Renaming to Aid with Numerical File Sorts Command Line and Curl Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Renaming to Aid with Numerical File Sorts Command Line and Curl Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Renaming to Aid with Numerical File Sorts Actions Tutorial' href='#ranfsat'>Renaming to Aid with Numerical File Sorts Actions Tutorial<\/a> had good interaction characteristics, in our books (<font size=3>&#8230; but as of this news bulletin, not in our pamphlettes <\/font><font size=2>and we hope to resume normal transmission forthwith <\/font><font size=1>like &#8230;<\/font>) <a style=\"text-decoration:underline;cursor:pointer;\" onclick='alert(\"You say mesa but I say but ... because cannot bring myself to say butte, thank you very much.\");'>but<\/a>, out of PHP&#8217;s three modes of use (which we talked about at <a target=_blank title='CSH\/KSH\/PHP Numerical Bubble Sort Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/cshkshphp-numerical-bubble-sort-tutorial\/'>CSH\/KSH\/PHP Numerical Bubble Sort Tutorial<\/a>) &#8230;<\/p>\n<ul>\n<li>Surfing the Net &#8230; is very interactive and we can use HTML form elements for navigation purposes &#8230; for example, URL (on  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) &#8230; <i>http:\/\/localhost:8888\/rename_to_aid_sorting.php?dirone=.%2F&amp;dirtwo=Django_Python-&amp;asteriskybit=%5B0123456789%5D*.*<\/i> &#8230; but more than likely the environment where users will think to use this PHP application is via &#8230;<\/li>\n<li>Command Line Usage &#8230; for example, be in MAMP&#8217;s \/Applications\/MAMP\/htdocs\/ directory with &#8230; <i>php rename_to_aid_sorting.php .\/Django_Python-<\/i> # or &#8230;<\/li>\n<li><a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/CURL' title='Curl information from Wikipedia ... thanks'>Curl<\/a> Usage &#8230; for example, be in MAMP&#8217;s \/Applications\/MAMP\/htdocs\/ directory with &#8230; <i>curl http:\/\/localhost:8888\/rename_to_aid_sorting.php?inspec=.\/Django_Python-<\/i> # you can see in action below &#8230;<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/MvWzTFdWMBQ\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/p>\n<p>Up near the top of the code processing input parameters the PHP code differentiation goes &#8230;<\/p>\n<p><code><br \/>\nif (isset($_GET['inspec']) && !isset($_GET['dirone']) && !isset($_GET['dirtwo'])) {   \/\/ reserved for curl instructions<br \/>\n  \/\/ Curl usage is hard to differentiate from \"Surfing the Net\" ... they both ask for a URL whereas Command Line has arguments ... so sometimes Curl usage is best<br \/>\n\/\/        organized with one $_GET[] (for us $_GET['inspec']) and limit it to just the one.  Why so?  Well, \"&\" on command line is awkward.<br \/>\n\/\/        To involve more than one argument in Curl use an internal delimitation character like ^ or ! perhaps to proceed.  We were able to just keep it to one today.<br \/>\n\/\/<br \/>\n\/\/ ... curl argument processing code goes here<br \/>\n\/\/<br \/>\n} else if ($argv) {  \/\/ command line usage<br \/>\n\/\/<br \/>\n\/\/ ... command line argument processing code goes here<br \/>\n\/\/<br \/>\n} else {   \/\/ surfing the net usage<br \/>\n\/\/<br \/>\n\/\/ ... surfing the net argument processing code goes here<br \/>\n\/\/<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; and down near the bottom, differentiation regarding the look of the outputs, it goes &#8230;<\/p>\n<p><code><br \/>\nif ($argv || (isset($_GET['inspec']) && !isset($_GET['dirone']) && !isset($_GET['dirtwo']))) { \/\/ command line or curl ... just show commands for user to try or not ... they may want a pipe like \" | tee do_these_renames.ksh\"  (and then follow up \"ksh -x do_these_renames.ksh\")<br \/>\n$outp=\"\";<br \/>\nif (strpos(strtoupper(('' . PHP_OS)), \"WINDOW\") !== false) {<br \/>\n$lines=explode(\"\\nren\" . \"ame \");<br \/>\nfor ($oi=1; $oi&lt;sizeof($lines); $oi++) {<br \/>\n  $outp.=\"ren\" . \"ame \" . explode(\"\\n\", $lines[$oi])[0] . \"\\n\";<br \/>\n}<br \/>\n} else {<br \/>\n$lines=explode(\"\\nm\" . \"v \",$htmlis);<br \/>\nfor ($oi=1; $oi&lt;sizeof($lines); $oi++) {<br \/>\n  $outp.=\"m\" . \"v \" . explode(\"\\n\", $lines[$oi])[0] . \"\\n\";<br \/>\n}<br \/>\n}<br \/>\necho $outp;<br \/>\n} else { \/\/ surfing the net form interactions below<br \/>\necho $htmlis;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>If you watch the video above, you&#8217;ll see us touching on some piping ideas too, with respect to Command Line and Curl modes of use, taking place at the command line.  These modes of use just output a set of operating system proposed rename (or non-Windows mv) commands to achieve the same default decisions the Surfing the Net program first shows after you Click\/Touch the &#8220;Analyze&#8221; button.  These commands have not been done by the application, as we leave this up to the user, as much as anything because the joys of piping can be used.  Take <b>a look at<\/b> &#8230;<\/p>\n<ul>\n<li>Command Line Usage &#8230; for example, be in MAMP&#8217;s \/Applications\/MAMP\/htdocs\/ directory with &#8230; <i>php rename_to_aid_sorting.php .\/Django_Python-<\/i><b> | tee do_renames.ksh<\/b> # or &#8230;<\/li>\n<li>Curl Usage &#8230; for example, be in MAMP&#8217;s \/Applications\/MAMP\/htdocs\/ directory with &#8230; <i>curl http:\/\/localhost:8888\/rename_to_aid_sorting.php?inspec=.\/Django_Python-<\/i><b> | tee do_renames.ksh<\/b> # you can see in action below &#8230;<\/li>\n<\/ul>\n<p>To make these (default) renamings happen (and now the operating system will supply any error messages, and here, we use our favourite scripting shell on non-Windows &#8230;ksh &#8230; <a target=_blank title='korn' href='http:\/\/www.computerhope.com\/unix\/uksh.htm'>Korn Shell<\/a>) &#8230;<\/p>\n<p><code><br \/>\nksh -x do_renames.ksh<br \/>\n<\/code><\/p>\n<p>For Windows &#8230;<\/p>\n<ul>\n<li>Command Line Usage &#8230; for example, be in MAMP&#8217;s \/Applications\/MAMP\/htdocs\/ directory with &#8230; <i>php rename_to_aid_sorting.php .\/Django_Python-<\/i><b> &gt; do_renames.bat<\/b> # or &#8230;<\/li>\n<li>Curl Usage &#8230; for example, be in MAMP&#8217;s \/Applications\/MAMP\/htdocs\/ directory with &#8230; <i>curl http:\/\/localhost:8888\/rename_to_aid_sorting.php?inspec=.\/Django_Python-<\/i><b> &gt; do_renames.bat<\/b> # you can see in action below &#8230;<\/li>\n<\/ul>\n<p>To make these (default) renamings happen, opening the Windows command line application (and now Window&#8217;s command line (DOS) operating system will supply any error messages) &#8230;<\/p>\n<p><code><br \/>\ndo_renames.bat<br \/>\n<\/code><\/p>\n<p>The third 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, still, &#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.  Its real power, though, is by you downloading it to a local web server environment such as MAMP supplies and code and test things yourself.  Feel free.<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>What is behind how PHP performs the operating system renaming commands &#8230; (good ol&#8217;) &#8230;<\/p>\n<p><code><br \/>\n<a target=_blank title='PHP glob() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php'>exec<\/a>(urldecode($_POST['cmd']));<br \/>\n<\/code><\/p>\n<p>Notice &#8220;the home of PHP&#8221;&#8216;s webpage&#8217;s blurb about alternatives &#8230;<\/p>\n<blockquote cite=\"http:\/\/php.net\/manual\/en\/function.exec.php\">\n<p>    system() &#8211; Execute an external program and display the output<br \/>\n    passthru() &#8211; Execute an external program and display raw output<br \/>\n    escapeshellcmd() &#8211; Escape shell metacharacters<br \/>\n    pcntl_exec() &#8211; Executes specified program in current process space<br \/>\n    backtick operator<\/p>\n<\/blockquote>\n<p> &#8230; and you might be interested in I.T. &#8220;land&#8221; with the word <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Fork_(disambiguation)'>fork<\/a><\/strike> <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Trident'>fork<\/a><\/strike> <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Motorcycle_fork'>fork<\/a><\/strike> <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Fork'>fork<\/a><\/strike> <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Garden_fork'>fork<\/a><\/strike> <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Tuning_fork'>fork<\/a><\/strike> <strike><a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Fork_(file_system)'>fork<\/a><\/strike> <strike><a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=C-Ta4XbRRj4'><font size=1>p<\/font>ork<\/a><\/strike> &#8230; aah &#8230; <a target=_blank title='Fork information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Fork_(system_call)'>fork<\/a>.\n<\/p>\n<hr>\n<p id='ranfsat'>Previous relevant <a target=_blank title='Renaming to Aid with Numerical File Sorts Actions Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/renaming-to-aid-with-numerical-file-sorts-actions-tutorial\/'>Renaming to Aid with Numerical File Sorts Actions 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 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<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='#d37632' onclick='var dv=document.getElementById(\"d37632\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/curl\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d37632' 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='#d42181' onclick='var dv=document.getElementById(\"d42181\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/genericize\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d42181' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The renaming of files in any automated or bulk or batch line of thinking &#8230; is most often tackled with server applications, not web applications &#8230; due to security risks &#8230; true with today&#8217;s work below too with the difference &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/renaming-scenario-in-single-folder-primer-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,29,37],"tags":[234,2718,707,725,744,932,997,1872,1319],"class_list":["post-42181","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-command-line","tag-genericize","tag-linux","tag-mac-os-x","tag-mamp","tag-php","tag-programming","tag-rename","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/42181"}],"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=42181"}],"version-history":[{"count":10,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/42181\/revisions"}],"predecessor-version":[{"id":42191,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/42181\/revisions\/42191"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=42181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=42181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=42181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}