简体   繁体   English

使用“glob”显示没有扩展名的文件?

[英]Using 'glob' to display files with no extension?

I am using the following code to display the files in descending order of date.我使用以下代码按日期降序显示文件。 But When I upload any file without extension its not visible because of glob, is there any way to show the hidden files?但是当我上传任何没有扩展名的文件时,由于 glob 不可见,有没有办法显示隐藏文件?

Code:代码:

<?php
$dir = "/opt/lampp/htdocs/jquery"; 
chdir($dir); 
array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files); 
foreach($files as $filename) 
{ 
    echo "<li>".$filename."</li>";  
}  
?>

@bodi0 gave you the code for ONLY items with no dots, you might be looking for @bodi0 为您提供了只有没有点的项目的代码,您可能正在寻找

...glob("*")

to get all files.获取所有文件。 Then, you will need to remove "."然后,您需要删除“。” and ".."和 ”..”

This is impossible with inclusive only glob (python), the answerers (is that a word), misunderstood your question.这是不可能的,只有 glob (python),回答者(是那个词)误解了你的问题。

/* gets all files/folders and returns folders with no "/" at the end, /*/ gets only folders and adds the "/" at the end, but for files with NO extension ie path/foo (NO DOT) it is not straightforward to separate the files from the folders with glob. /* 获取所有文件/文件夹并返回末尾没有“/”的文件夹,/*/ 仅获取文件夹并在末尾添加“/”,但对于没有扩展名的文件,即 path/foo (NO DOT)使用 glob 将文件与文件夹分开并不简单。

It is possible, of course, just pass this regex pattern to the glob() :当然,可以将此正则表达式模式传递给glob()

glob("([^\\.])");

The pattern ([^\\.]) means every file name, which does not have a dot in it.模式([^\\.])表示每个文件名,其中没有点。

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

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