php教程创建目录,删除文件夹及查找不合法的目录并删除
//$pattern = "/file-([0-2]d{3})-([1-9]d?)/"; 这个正则表达式,对文件夹的月日进行捕获,再进一步判断处理
02 for($i =2005;$i
03 {
04 for($j = 1;$j
05 {
06 $dest_dir = "text/file-".$i."-$j";
07 if(!is_dir($dest_dir)) mkdir($dest_dir,0777);
08 }
09 }
10 //创建一些不满足条件的文件夹
11
12 for($t = 0;$t
13 {
14 $dest_dir = "text/file-".$t;
15 if(!is_dir($dest_dir)) mkdir($dest_dir,0777);
16 }
17
18 //遍历文件夹处理 .
19 function listFile($dir)
20 {
21 $a = array();
22 $handle = opendir($dir);
23 while($file = readdir($handle))
24 {
25 handle_dir($dir,$file,&$a);
26 }
27
28 echo "the rege_array is ";
29 print("
"); <p>30 print_r($a); </p><p>31 print("</p>");
32 }
33
34 function handle_dir($dir,$file,$a)
35 {
36
37 if($file == "." || $file == "..") return ;
38 $minYear = 2008;
39 $maxDay = 13;
40
41 $pattern = "/file-([0-2]d{3})-([1-9]d?)/";
42 $destPath = $dir."/".$file;
43
44 if(!is_dir($destPath))
45 {
46 //echo "$destPath is not a dir ;";
47 return;
48 }
49
50 //删除不满足格式的文件
51 if(!preg_match($pattern,$file))
52 {
53 //echo "$fileis not the right rege. the program will unlink -- $destPath --
";
54 // unlink($destPath);
55 return;
56 }
57
58 preg_match_all($pattern,$file,$matchs);
59
60 //echo "$file is the right rege";
61 //print_r($matchs);
62 //echo "the year is ".$matchs[1][0]." and the day is ".$matchs[2][0]."";
63 if(intval($matchs[1][0]) >$minYear && intval($matchs[2][0])
64 {
65 $a[]= $destPath;
66 }else { //不满足条件的
67 //unlink($destPath);
68
69 }
70 }
71
72 listFile("text");

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구
