5,25d4 < // Renaming to marry up numerical sort ideals with alphabetical sorting filenames relative to program's directory < // < // PHP is great to program for 1) "Surfing the Net" ... but sometimes ... < // < // the original envisagement was to use it at the ... < // 2) Command Line ... or that in between mode of use ... < // 3) Curl < // < // First we'll show you its execution methods ... then how to differentiate in PHP code... < // < // Command line example (where program is located) ... php rename_to_aid_sorting.php ./Django_Python- < // Curl example ... curl http://localhost:8888/rename_to_aid_sorting.php?inspec=./Django_Python- < // Surfing the Net (url) example ... http://localhost:8888/rename_to_aid_sorting.php?dirone=.%2F&dirtwo=Django_Python-&asteriskybit=%5B0123456789%5D*.* < // < // 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 < // organized with one $_GET[] (for us $_GET['inspec']) and limit it to just the one. Why so? Well, "&" on command line is awkward. < // 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. < // < // Command line example (where program is located) ... php rename_to_aid_sorting.php ./Django_Python- < // Curl example ... curl http://localhost:8888/rename_to_aid_sorting.php?inspec=./Django_Python- < // Surfing the Net (url) example ... http://localhost:8888/rename_to_aid_sorting.php?dirone=.%2F&dirtwo=Django_Python-&asteriskybit=%5B0123456789%5D*.* 38,182d16 < $asteriskybit="[0123456789]*.*"; < //$asteriskybit="[0123456789]*_[0123456789]*.png"; < $cldone=true; < $upto=0; < < if (isset($_GET['inspec']) && !isset($_GET['dirone']) && !isset($_GET['dirtwo'])) { // reserved for curl instructions < if (strpos($_GET['inspec'], "\\") !== false || strpos($_GET['inspec'], "/") !== false) { < $dprefix=$_GET['inspec']; < } else { < $dprefix=urldecode($_GET['inspec']); < } < if (strpos($dprefix, "/") !== false) { < $upto=3; < $putthisback=explode("/",$dprefix)[-1 + sizeof(explode("/",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } else if (strpos($dprefix, "\\") !== false) { < $upto=3; < $putthisback=explode("\\",$dprefix)[-1 + sizeof(explode("\\",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } < } else if ($argv) { // command line usage < $cldone=false; < foreach ($argv as $arg) { // PHP command line < if ($upto < 5 && ($upto > 0 || strpos(urldecode($arg), "^") !== false || strpos(urldecode($arg), "\\") !== false || strpos(urldecode($arg), "/") !== false)) { < $cldone=true; < if (urldecode($arg) != "") { < if ($upto == 2) { < $putthisback=urldecode($arg); < $upto=3; < } else if ($upto == 3) { < $asteriskybit=urldecode($arg); < $upto=6; < } else { < $aparts=explode("^", urldecode($arg)); < if (sizeof($aparts) >= 3) { < $upto=6; < $dprefix=$aparts[0] . $aparts[1]; < $asteriskybit=$aparts[2]; < if (strpos($dprefix, "/") !== false) { < $putthisback=explode("/",$dprefix)[-1 + sizeof(explode("/",$dprefix))]; < } else if (strpos($dprefix, "\\") !== false) { < $putthisback=explode("\\",$dprefix)[-1 + sizeof(explode("\\",$dprefix))]; < } < } else if (sizeof($aparts) == 2) { < $upto=3; < $dprefix=$aparts[0] . $aparts[1]; < if (strpos($dprefix, "/") !== false) { < $upto=3; < $putthisback=explode("/",$dprefix)[-1 + sizeof(explode("/",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } else if (strpos($dprefix, "\\") !== false) { < $upto=3; < $putthisback=explode("\\",$dprefix)[-1 + sizeof(explode("\\",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } < } else if (substr($arg,-1) == "\\" || substr($arg,-1) == "/") { < $upto=2; < $dprefix=$aparts[0]; < if (strpos($dprefix, "/") !== false) { < $upto=3; < $putthisback=explode("/",$dprefix)[-1 + sizeof(explode("/",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } else if (strpos($dprefix, "\\") !== false) { < $upto=3; < $putthisback=explode("\\",$dprefix)[-1 + sizeof(explode("\\",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } < if (strpos($dprefix, "/") !== false) { < $upto=3; < $putthisback=explode("/",$dprefix)[-1 + sizeof(explode("/",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } else if (strpos($dprefix, "\\") !== false) { < $upto=3; < $putthisback=explode("\\",$dprefix)[-1 + sizeof(explode("\\",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } < } else if (strpos($arg,"\\") !== false || strpos($arg,"/") !== false) { < $upto=2; < $dprefix=$aparts[0]; < if (strpos($dprefix, "/") !== false) { < $upto=3; < $putthisback=explode("/",$dprefix)[-1 + sizeof(explode("/",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } else if (strpos($dprefix, "\\") !== false) { < $upto=3; < $putthisback=explode("\\",$dprefix)[-1 + sizeof(explode("\\",$dprefix))]; < if (strpos($putthisback, "[") !== false) { < $upto=6; < $sput=explode("[",$putthisback[0]); < $asteriskybit=substr($putthisback,strlen($sput)); < $putthisback=$sput; < } < } < } < } < } < } < } < } else { // surfing the net usage < 203,211d36 < if (isset($_GET['asteriskybit'])) { < $asteriskybit=urldecode($_GET['asteriskybit']); < } else if (isset($_POST['asteriskybit'])) { < $asteriskybit=urldecode($_POST['asteriskybit']); < } < < < } < 228a54,60 > $asteriskybit="[0123456789]*.*"; > //$asteriskybit="[0123456789]*_[0123456789]*.png"; > if (isset($_GET['asteriskybit'])) { > $asteriskybit=urldecode($_GET['asteriskybit']); > } else if (isset($_POST['asteriskybit'])) { > $asteriskybit=urldecode($_POST['asteriskybit']); > } 238c70 < if (strpos("~" . str_replace("m" . "v " . "", "ren" . "ame ",urldecode($_POST['cmd'])), "~ren" . "ame " . urldecode($_POST['infile']) . " ") !== false) { --- > if (strpos("~" . str_replace("mv ", "rename ",urldecode($_POST['cmd'])), "~rename " . urldecode($_POST['infile']) . " ") !== false) { 266c98 < if (strpos("~" . str_replace("m" . "v " . "", "ren" . "ame ",urldecode($_POST['cmd'])), "~ren" . "ame " . urldecode($_POST['infile']) . " ") !== false) { --- > if (strpos("~" . str_replace("mv ", "rename ",urldecode($_POST['cmd'])), "~rename " . urldecode($_POST['infile']) . " ") !== false) { 301c133 < if (document.getElementById('c3_' + ij).innerHTML.replace('m' + 'v ','ren' + 'ame ').indexOf('ren' + 'ame ') == 0) fixc3=true; --- > if (document.getElementById('c3_' + ij).innerHTML.replace('mv ','rename ').indexOf('rename ') == 0) fixc3=true; 338,340c170,172 < if (redo.indexOf('ren' + 'ame \"') != -1) { < spares=redo.split('ren' + 'ame \"'); < spares[0]+='ren' + 'ame \"' + spares[1].split('\"')[0] + '\" '; --- > if (redo.indexOf('rename \"') != -1) { > spares=redo.split('rename \"'); > spares[0]+='rename \"' + spares[1].split('\"')[0] + '\" '; 343,345c175,177 < } else if (redo.indexOf('m' + 'v \"') != -1) { < spares=redo.split('m' + 'v \"'); < spares[0]+='m' + 'v \"' + spares[1].split('\"')[0] + '\" '; --- > } else if (redo.indexOf('mv \"') != -1) { > spares=redo.split('mv \"'); > spares[0]+='mv \"' + spares[1].split('\"')[0] + '\" '; 348,350c180,182 < } else if (redo.indexOf('ren' + 'ame ') != -1) { < spares=redo.split('ren' + 'ame '); < spares[0]+='ren' + 'ame ' + spares[1].split(' ')[0] + ' '; --- > } else if (redo.indexOf('rename ') != -1) { > spares=redo.split('rename '); > spares[0]+='rename ' + spares[1].split(' ')[0] + ' '; 353,355c185,187 < } else if (redo.indexOf('m' + 'v ') != -1) { < spares=redo.split('m' + 'v '); < spares[0]+='m' + 'v ' + spares[1].split(' ')[0] + ' '; --- > } else if (redo.indexOf('mv ') != -1) { > spares=redo.split('mv '); > spares[0]+='mv ' + spares[1].split(' ')[0] + ' '; 453a286,287 > > 475c309 < //echo str_replace($dprefix, "", $filename) . " ... " . $ncnt . "?" . $thisext . "." . $nfields . ";" . $delimis; --- > //echo str_replace($dprefix, "", $filename) . " ... " . $thisext . "." . $nfields . ";" . $delimis; 540a375 > 551,557c386 < if ($argv || (isset($_GET['inspec']) && !isset($_GET['dirone']) && !isset($_GET['dirtwo']))) { < if (strpos(strtoupper(('' . PHP_OS)), "WINDOW") !== false) { < $newcb="\nrename " . qi($dprefix . $fileis[$recnt]) . " " . qi($putthisback . $changesto[$iu]) . "\n"; < } else { < $newcb="\nmv " . qi($dprefix . $fileis[$recnt]) . " " . qi($dprefix . $changesto[$iu]) . "\n"; < } < } else if (strpos(strtoupper(('' . PHP_OS)), "WINDOW") !== false && strpos($_SERVER['SERVER_NAME'],"rjmprogramming.com.au") === false) { --- > if (strpos(strtoupper(('' . PHP_OS)), "WINDOW") !== false && strpos($_SERVER['SERVER_NAME'],"rjmprogramming.com.au") === false) { 561c390 < $newcb.="ren" . "ame " . qi($dprefix . $fileis[$recnt]) . " " . qi($putthisback . $changesto[$iu]); --- > $newcb.="rename " . qi($dprefix . $fileis[$recnt]) . " " . qi($putthisback . $changesto[$iu]); 567c396 < $newcb="ren" . "ame " . qi($dprefix . $fileis[$recnt]) . " " . qi($putthisback . $changesto[$iu]); --- > $newcb="rename " . qi($dprefix . $fileis[$recnt]) . " " . qi($putthisback . $changesto[$iu]); 572c401 < $newcb.="m" . "v " . "" . qi($dprefix . $fileis[$recnt]) . " " . qi($dprefix . $changesto[$iu]); --- > $newcb.="mv " . qi($dprefix . $fileis[$recnt]) . " " . qi($dprefix . $changesto[$iu]); 578c407 < $newcb="m" . "v " . "" . qi($dprefix . $fileis[$recnt]) . " " . qi($dprefix . $changesto[$iu]); --- > $newcb="mv " . qi($dprefix . $fileis[$recnt]) . " " . qi($dprefix . $changesto[$iu]); 593,607d421 < if ($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") < $outp=""; < if (strpos(strtoupper(('' . PHP_OS)), "WINDOW") !== false) { < $lines=explode("\nren" . "ame "); < for ($oi=1; $oi