I am trying to build a filter for sorting/removing files;
However, upon testing I have noticed 2 files which are getting through the net despite being named with a "(Japan)" country identifier at the end. I think this is because of their strange characters (a dollar sign in one and 3 periods in a row in the other)
The 2 files are:
Quiz$Millionaire - Waku Waku Party (Japan).zip
...Iru! (Japan).zip
I get the error below when running the script. It echo's the file correctly, but then when attempting the mv
it reports it with "$Millionaire" missing from the middle of the string!
Quiz$Millionaire (Japan) (v1.0).zip is a foreign language release. Moved to Removed folder.
mv: cannot stat 'Quiz (Japan) (v1.0).zip': No such file or directory
Unfortunately for the other file (...Iru! (Japan).zip) I don't even get a match/echo
I have been told I need to use $thisGame = escapeshellcmd($thisGame);
in the code below, but when I do it messes up my regex matching for everything else - so I think I have to modify my regex - but I am a beginner and don't really know how to fix it! Many thanks in advance for your help - code below:
$gameList = trim(shell_exec("ls -1"));
$gameArray = explode("\n", $gameList);
shell_exec('mkdir -p Removed');
// Do this magic for every file
foreach ($gameArray as $thisGame)
{
if (!$thisGame) continue;
// Probably already been removed
if (!file_exists($thisGame)) continue;
// Non-Engish speaking countries e.g. (France) or (Japan)
if (preg_match('%\((Asia|Austria|Brazil|China|Denmark|Finland|France|Germany|Greece|Hungary|Israel|Italy|Japan|Japan, Asia|Korea|Netherlands|Norway|Poland|Portugal|Russia|Scandinavia|Spain|Sweden)\)%', $thisGame))
{
echo "{$thisGame} is a foreign language release. Moved to Removed folder.\n";
shell_exec("mv \"{$thisGame}\" Removed/");
continue;
}
}
Many thanks for your help!