gpt4 book ai didi

php - Windows下php scandir()是否排除隐藏文件?

转载 作者:可可西里 更新时间:2023-11-01 09:52:51 24 4
gpt4 key购买 nike

在 Windows 系统上,备份代理创建了与原始文件名称几乎相同且路径相同的临时隐藏文件。这可能会干扰使用 PHP scandir() 的进程。

现在我想知道 Windows 上设置了隐藏标志的文件是否被 PHP scandir() 排除。

有一些关于 Linux 风格的隐藏文件的文章,scandir() 应该如何忽略以点开头的文件,但很少没有关于 Windows 文件的信息。

最佳答案

我已经在 Windows 7 和 Windows 8 & 8.1 上尝试过这段代码,它确实通过标记出来排除了隐藏文件。

   <?php

$location="path/to/a/folder/";

if( function_exists("scandir") ){

$file = scandir($location);

foreach($file as $this_file) {
/***Putting the condition here restricts hidden files and files starting with '.' and '~'...****/
if (is_hidden_file($location.$this_file) || $this_file == '.' || $this_file == '..' || $this_file[0]=='.' || $this_file[0]=='~' )
continue;

else {
var_dump($this_file);
}

}
}

function is_hidden_file($fn) {
$dir = "\"".$fn."\"";
$attr = trim(shell_exec("FOR %A IN (".$dir.") DO @ECHO %~aA"));
if($attr[3] === 'h')
return true;

return false;
}
?>

我看到您在问题中提到有一些方法可以排除以“.”开头的文件。和 linux 中的东西,但关于 windows 的信息很少。然后检查一下它不仅消除了以“。”开头的文件。 & '..' 但也标记出实际隐藏的文件,并且肯定会在 Windows 中工作。

关于php - Windows下php scandir()是否排除隐藏文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30290663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com