简体   繁体   English

scandir显示错误结果

[英]scandir showing wrong results

My code: 我的代码:

if ($d = opendir('.')) {
       while (($file = readdir($d)) !== false) {
            if ( $file != "."  && $file != ".." ){
                echo "filename: $file \n";
                $files[]=$file;
            }
       }
    closedir($d);
}

outputs: 输出:

 filename: audio_files filename: backup_files filename: compressed_files filename: database_files filename: data_files filename: developer_files filename: disk_image_files filename: executable_files filename: font_files filename: genstats.php filename: raster_image_files filename: spreadsheet_files filename: text_files filename: text_filesdesktop__dup.ini filename: video_files filename: web_files 

whereas text_filesdesktop__dup.ini doesn't even exist. text_filesdesktop__dup.ini甚至不存在。

 C:\\Users\\Steve\\Desktop\\Files>del text_filesdesktop__dup.ini Could Not Find C:\\Users\\Steve\\Desktop\\Files\\text_filesdesktop__dup.ini 

I have tried using scandir() , deleting the file and recreating it, etc, to no avail. 我尝试使用scandir() ,删除文件并重新创建文件等,但无济于事。 I simply can't get that .ini file to go away. 我根本无法删除该.ini文件。

might be you are having hidden files in your directory 可能是您的目录中有隐藏文件

what platform are your using , WiNDOWS OR Linux , 您使用什么平台,WiNDOWS或Linux,

If you just want to exclude files starting with a dot, ".", 如果您只想排除以点“。”开头的文件,

try this: 尝试这个:

$files = readdir('/path/to/folder');
$files = array_filter($files, create_function('$a','return ($a[0]!=".");'));

the above function only returs the files , chich are not starting with . 上面的函数只还原文件,而不是以。

but on windows hidden files works differently , i dont know how to play with it . 但是在Windows上隐藏文件的工作方式不同,我不知道如何玩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM