1. [代码][PHP]代码
<?php // dir 一定需要用单引号包围,因为目录中可能有特殊字符(如c:\file中\f) date_default_timezone_set("Asia/Shanghai") ; $dir = 'D:\workspace\xx\src\contents'; // 目标目录放在当前桌面 $target_dir = 'C:\Users\XJ\Desktop\XJ'; // $target_dir = 'C:\Users\当前用户的登录名\Desktop\你想建立的文件夹名字'; // 查找多久之前的文件 $target_time = strtotime('-1 hours'); function create_dir($root, $filename, $target_time, $target_dir) { if (file_exists($filename)) { if (is_dir($filename)) { $remove_root = preg_quote($root); $new_filename = preg_replace("@$remove_root@", "", $filename); @mkdir($target_dir . $new_filename); foreach (glob("$filename/*") as $key=>$value) { create_dir($root, $value, $target_time, $target_dir); } } else { $modify_time = filemtime($filename); // 新增文件使用filectime $create_time = filectime($filename); if ($modify_time >= $target_time || $create_time >= $target_time) { $root = preg_quote($root); $str = file_get_contents($filename); $filename = preg_replace("@$root@", "", $filename); if (!is_file($target_dir . $filename)) { file_put_contents($target_dir . $filename,$str); } echo $filename . "<br/>"; } } } else { echo '参数错误'; return false; } } // 第二参数控制是全删,还是只是删除空目录 function remove_dir($target_dir, $all_flg = false){ foreach (glob("$target_dir/*") as $key=>$value) { if (is_dir($value) && count(glob("$value/*")) == 0) { // 删除第一层目录为空的目录 rmdir($value); } else if (is_dir($value) && count(glob("$value/*")) > 0) { // 校验当前目录的所有子目录 foreach(glob("$value/*") as $sub_key=>$sub_value) { remove_dir($sub_value, $all_flg); } // 经过上一步的处理,再回到当前目录,检验当前目录的子目录是否有空的目录 remove_dir($value, $all_flg); // 如果当前目录经过上面的处理后是空目录,则删除 if (is_dir($value) && count(glob("$value/*")) == 0) { rmdir($value); } } if ($all_flg) { if (is_file($value)) { unlink($value); } } } } // 先清空目标目录 remove_dir($target_dir, true); // 重建目录 create_dir($dir, $dir, $target_time, $target_dir); sleep(1); // 筛选目录 remove_dir($target_dir);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
