特定のディレクトリ内のすべてのファイルを一覧表示するディレクトリ一覧コードが 1 つあります。ファイル名に az と 0-9 以外の特定の文字を含むものがあります。「i」の上にドットがない小さな「i」のようなものです。ファイル名は「ClrmamePro Kullanımı English.mp4」です。「Kullanımı」と「English」を見てください。「i」と「ı」の違いがわかります。
問題は、ディレクトリのリストを作成すると、php が文字 "ı" を "i" に自動的に変換するため、名前の変更を実行するときにエラーが発生することです。
rename(E:/workspace/project/ClrmamePro Kullanimi English.mp4,
E:/workspace/project/movie_11.mp4) [<a href='function.rename'>function.rename</a>]: The system cannot find the file specified.
ファイル名を修正する正規表現がありますが、PHP が自動的に "ı" を "i" に変換するため、それをキャッチできません。
ディレクトリリストのコードは次のとおりです
function getDirectoryListing($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if (strpos($file,'.') !== 0) {
$results[] = $file;
}
}
closedir($handler);
// done!
return $results;
}
echo '<pre>';
print_r(getDirectoryListing('movies'));
echo '</pre>';
o/pi は次のようになります。
Array
(
[0] => ClrmamePro Kullanimi English.mp4
[1] => Download Gears of War 3 - eSoftZone.webm
[2] => Facebook_ Science and the Social Graph.MP4
)
インデックス 0 の最初のファイルを参照してください。ディレクトリ内の実際のファイル名は
ClrmamePro Kullanımı English.mp4