|
|
|
|
|
|
| |
Some people working on windows have encountered this problem, where all files and directories are all uppercase. While your website could run on windows, it couldn't be the case for *nix. So this script will help to batch rename files and directories to lowercase or uppercase.
|
#!/usr/bin/php
<?php
$argv = $GLOBALS[HTTP_SERVER_VARS][argv];
$argc = $GLOBALS[HTTP_SERVER_VARS][argc];
if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
Batch Uppercase/lowercase files and directories for a given path.
Usage :
<?php echo $argv[0]; ?> <path> <upper/lower> <p>
Sample (lowercase all files and directories in current folder):
<?php echo $argv[0]; ?>
<path> Path to your files/directories (default is current)
<upper/lower> Lowercase or uppercase (default is lowercase)
<p> print processed files/directories in the output
Options --help, -help, -h,
and -?, Will return this help
<?php
/**
* @return void
* @param array $base_dir
* @desc return recursive list of files and directories
*/
function recrusive_dirlist($base_dir)
{
global $getDirList_alldirs,$getDirList_allfiles;
function getDirList($base)
{
global $getDirList_alldirs,$getDirList_allfiles;
if(is_dir($base))
{
$dh = opendir($base);
while (false !== ($dir = readdir($dh)))
{
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') //note the change in this line
{
// $subs = $dir ;
$subbase = $base ."/". $dir;//note the change in this line
$getDirList_alldirs[]=$subbase;
getDirList($subbase);
}
elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..')//change in this line too
{
$getDirList_allfiles[]=$base ."/". $dir;//change in this line too
}
}
closedir($dh);
}
}
getDirList($base_dir);
$retval['dirs']=$getDirList_alldirs;
$retval['files']=$getDirList_allfiles;
return $retval;
}
/**
* @return void
* @param string $path
* @param string $type
* @param char $p
* @desc process to batch rename with uppercase or lowercase
*/
function batch_ul($path,$type,$p){
// retrives array of files and directories
if (trim($path)=="") {
$curr = getcwd(); // Current dir
} else $curr = $path; // user path
$data = recrusive_dirlist($curr);
// rename files
foreach ($data["files"] as $in) {
// lowercase just the last part
$newname = explode("/",$in);
switch($type){
case "upper":
$newname[sizeof($newname)-1] = strtoupper($newname[sizeof($newname)-1]);
break;
default:
$newname[sizeof($newname)-1] = strtolower($newname[sizeof($newname)-1]);
break;
}
$lcname = "/".implode("/",$newname);
shell_exec("mv $in ".$lcname);
if (trim($p)!="") {
echo "Copy done from $in to $lcname\n\r";
}
}
// then rename directories
$data["dirs"] = array_reverse($data["dirs"]);
foreach ($data["dirs"] as $in) {
// lowercase just the last part
$newname = explode("/",$in);
switch($type){
case "upper":
$newname[sizeof($newname)-1] = strtoupper($newname[sizeof($newname)-1]);
break;
default:
$newname[sizeof($newname)-1] = strtolower($newname[sizeof($newname)-1]);
break;
}
$lcname = "/".implode("/",$newname);
shell_exec("mv $in ".$lcname);
if (trim($p)!="") {
echo "Copy done from $in to $lcname\n\r";
}
}
}
?> | |
Usage Example
| <?php
$path = $argv[1];
$type = $argv[2];
$p = $argv[3];
batch_ul($path,$type,$p);
?> | | |
|
| List the content of the directory of your webserver where this small PHP Script resides. Categories : PHP, Filesystem, Directories, CSS | | | Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP, Directories, FTP, Filesystem, HTML and PHP | | | a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts Categories : PHP, URLs, Directories, Filesystem | | | grab directory listings into an array the example prints out each
subdirectory in the main dir - further work is to be performed on this one Categories : Filesystem, PHP, Directories, Search, Utilities | | | Listing the 10 most recently updated files in a given dir by using last-
modified variable and printing to html with link to the file Categories : PHP, Directories, Filesystem | | | getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory,
filtered by regular expression and either sorted or randomized. Good for
random pictures and graphics. Categories : PHP, Filesystem, Directories | | | Extended Get File List Function Categories : PHP, Filesystem, Search, Directories | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | A function which places the path and name of all subdirectories into an array Categories : PHP, Filesystem, Arrays, Directories | | | Directory viewer, customize how you display the file structure, easy to
understand. Found out about PHP 3 days ago, and this is my first prog. Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP | | | Using PHP to Delete a directory with all sub directories and files using FTP Categories : PHP, FTP, Directories, Filesystem | | | PHP4 DirectoryIterator Class Categories : PHP, PHP Classes, Filesystem, Directories | | | Directory Viewer, Directory Content Viewer, Directory Structure to HTML.
This code will basically create a complete set of HTMLs to let a user
navigate through any directory you want. Excellent code for large file
sharing pages. Categories : Directories, Filesystem, PHP | | | Open directory and File download Categories : PHP, Filesystem, Directories, HTML and PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | |
|
|