我有一个脚本,可以遍历目录中的每个文件名并删除不需要的文件。另外,它匹配CSV文件中的文件名,然后删除相邻单元格中的文件。
<?php
$gameList = trim(shell_exec("ls -a -1 -I . -I .. -I Removed"));
$gameArray = explode("\n", $gameList);
shell_exec('mkdir -p Removed');
echo "\033[01;32m\n\n<<<<<<<<<<Starting Scan>>>>>>>>>>\n\n";
// Do the magic for every file
foreach ($gameArray as $thisGame)
{
// Ensure continue if already removed
if (!$thisGame) continue;
if (!file_exists($thisGame)) continue;
// Manipulate names to look and play nice
$niceName = trim(preg_replace('%[\(|\[].*%', '', $thisGame));
$thisGameNoExtension = preg_replace('/\.' . preg_quote(pathinfo($thisGame, PATHINFO_EXTENSION) , '/') . '$/', '', $thisGame);
// Let the user know what game is being evaluated
echo "\033[00;35m{$thisGameNoExtension} ... ";
$f = fopen("ManualRegionDupes.csv", "r");
while ($row = fgetcsv($f))
{
if ($row[1] == $thisGameNoExtension)
{
$primaryFile = $row[0];
$ext = pathinfo($thisGame, PATHINFO_EXTENSION);
$fCheck = trim(shell_exec("ls -1 " . escapeshellarg($primaryFile) . "." . escapeshellarg($ext) . " 2>/dev/null"));
if ($fCheck)
{
echo "ECHO LION";
shell_exec("mv " . escapeshellarg($thisGame) . " Removed/");
continue;
}
else
{
echo "ECHO ZEBRA";
continue;
}
break;
}
}
fclose($f);
echo "Scanned and kept";
}
echo "\033[01;32m\n<<<<<<<<<<Process Complete>>>>>>>>>>\n\n";
?>
它正在工作,但是我不明白为什么我会在“ ECHO ZEBRA”或“ ECHO LION”之后立即看到最终的回声“ Scanned and Kept”-因为我在它们之后直接有“ continue”呼叫,这应该重新启动循环并继续下一个文件。我敢肯定,我只需要在某个地方重新摇动一下东西,但是我已经摆弄了几个小时,我完全陷入了困境。如果有任何帮助,我将非常感谢!非常感谢!
答案 0 :(得分:4)
答案 1 :(得分:0)
继续通话后,您除了休息之外什么都没有,还会运行什么?编辑,如果要在外循环上继续,请将其移到那里。为什么要下票,继续是在错误的循环中。