<?php
//Rename files and remove spaces, commas, equal signs, semi-colons, apostrophes, etc.:
//foreach(glob("{*.amr,*.AMR,*.mp3,*.MP3}",GLOB_BRACE ) as $file) {
foreach(glob("{*.png}",GLOB_BRACE ) as $file) {
if (strpos($file, " ") > 0) { //If there are more than 0 spaces in the name.
$x = "mv \"" . $file . "\" ";
$y = str_replace(" ", "_", $file); //Remove spaces.
$y = str_replace(",", "", $y); //Remove commas.
$y = str_replace("=", "", $y); //Remove equals.
$y = str_replace(";", "", $y); //Remove semi-colons.
$y = str_replace("'", "", $y); //Remove apostrophes.
$y = str_replace("(", "", $y); //Remove left parenthesis.
$y = str_replace(")", "", $y); //Remove right prenthesis.
$y = str_replace("$", "", $y); //Remove dollar signs.
$y = str_replace("[", "", $y); //Remove left brackets.
$y = str_replace("]", "", $y); //Remove right brackets.
$y = str_replace("&", "", $y); //Remove ampersands.
$y = str_replace("`", "", $y); //Remove accent aigou.
$y = str_replace("._", "_", $y); //Remove period underscore.
//echo "mv " . $x . " " . $y . "<br />";
echo $x . " " . $y . "<br />";
// DO NOT USE
BECAUSE IT WILL PUT A CARRIAGE RETURN IN THE FILENAME!
}
//The built-in Linux rename utility is useful for removing the carriage return on files.
//Usage: rename $'
' '' *.txt*
//https://unix.stackexchange.com/questions/189784/remove-newlines-in-file-names
//php -f renamefiles.php > ~/public_html/rename.html
//Rename files that start with a dash or hyphen, use a double-dash:
// mv -- -filename.txt filename.txt
}
/*
NOTE: I got rid of the carriage return by zipping the files up and unzipping them.
*/
?>