Hongmu Notes
Home Language Notes Why can't I delete a PHP file that starts with a certain pattern?
Language Notes PHP

Why can't I delete a PHP file that starts with a certain pattern?

Why can't I delete a PHP file that starts with a certain pattern?

In the previous article:PHP – Delete all files and directories in the current directory.", most files can be deleted! However, you may encounter an issue: the introductory article cannot be resolved! Let's analyze the reason! glob ` scandir()` is a universal file system function that returns the names of files or directories matching a specified pattern. Use it in PHP. glob When using the function, you may notice that it cannot locate items containing a dot.(.)The initial document (e.g..DS_Store). This is because files that start with a dot belong to the `class`. UNIX The system considers ithidden fileIt will not be displayed by conventional file system operations. Therefore, when you use it glob When searching the file system, the system by default hides files that start with a dot and does not return these file names. If you wish to find files that start with a dot, you can use the following method:

  1. Display search: Include file names that start with a dot in the glob function pattern (e.g., „. "or „.DS_Store"). This will return files that start with a dot, as well as all other files.
  2. Use an iterator: You can use the DirectoryIterator or RecursiveDirectoryIterator classes from the PHP SPL (Standard PHP Library) to iterate through a directory, and then call the getFilename() method to retrieve all file names, including those that start with a dot.
例如:
$dir = new RecursiveDirectoryIterator(__DIR__);
$iterator = new RecursiveIteratorIterator($dir);
$files = array();
foreach ($iterator as $file) {
    if (!$file->isDir() && $file->getFilename()[0] === '.') {
        $files[] = $file->getPathname();
    }
}

print_r($files);
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 190
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

Light-Gauge Steel Villa Construction and Renovation Website Template – 0803

Light-Gauge Steel Villa Construction and Renovation Website Template – 0803 Practical Collection Yiyou template

This EyouCMS template is ideal for the light-gauge steel villa construction, building, and renovation industries. Its modern and eco-friendly design style is perfect for showcasing light-gauge steel villa products, construction projects, and interior design solutions. It enables new construction enterprises to showcase their green building concepts and capabilities online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 46
jquery click to jump to the top of the web page

jquery click to jump to the top of the web page Language Notes JavaScript

You can use jQuery to jump to the top of the web page after clicking on an element. The following is a simple implementation method: $(document).ready(function() { // Listen to the click event of the element $('#my-element').click(function() { // Scroll to the top $('html, body').an…
👁 205
(PC+WAP) Biotechnology Engineering Category – pbootCMS Website Template; Download Source Code for Health Management, Pharmaceutical and Healthcare Websites – 0070

(PC+WAP) Biotechnology Engineering Category – pbootCMS Website Template; Download Source Code for Health Management, Pharmaceutical and Healthcare Websites – 0070 Practical Collection pbootcms Template

A PbootCMS website template dedicated to biotechnology, health management, and pharmaceuticals, compatible with both PC and mobile devices. Its rigorous and professional design effectively showcases biotechnology products and healthcare services. This template helps biopharmaceutical companies establish a professional online presence and demonstrate their R&D capabilities and product portfolio. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin
👁 47
(Adaptive Mobile Version) Responsive Blue Foreign Trade English Website Template – 1004

(Adaptive Mobile Version) Responsive Blue Foreign Trade English Website Template – 1004 Practical Collection pbootcms Template

A responsive blue English-language PbootCMS e-commerce website template supporting both PC and WAP devices. Its international and professional design makes it ideal for businesses to create official English-language e-commerce websites, helping Chinese manufacturing enterprises showcase their brand image and product capabilities in the global market. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: P...
👁 50
High-end whole-house solid wood custom furniture website template – 0804

High-end whole-house solid wood custom furniture website template – 0804 Practical Collection Yiyou template

An EyouCMS website template designed for high-end whole-house solid wood custom furniture businesses. Its luxurious and sophisticated design style effectively showcases custom solid wood furniture, whole-house renovation case studies, and design concepts, helping premium furniture customization brands attract high-quality customers online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (E...
👁 40
(PC+WAP) Electric Gate & Extending Door Website – pbootCMS Template; Download Blue Automatic Extending Door Website Source Code – 0071

(PC+WAP) Electric Gate & Extending Door Website – pbootCMS Template; Download Blue Automatic Extending Door Website Source Code – 0071 Practical Collection pbootcms Template

A PbootCMS website template designed for electric gate, telescopic gate, and automatic door products, featuring a blue color scheme and compatibility with both PC and WAP devices. Its modern, tech-inspired design is ideal for showcasing automatic door equipment and security solutions. This template helps telescopic gate manufacturers highlight their product advantages online and attract more project inquiries. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin...
👁 45