찾다
php教程php手册php创建目录,删除文件夹及查找不合法的目录并删除

php创建目录,删除文件夹及查找不合法的目录并删除

Jun 13, 2016 am 11:23 AM
php만들다삭제지도 시간접는 사람찾다~의목차

 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");


성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

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

뜨거운 도구

PhpStorm 맥 버전

PhpStorm 맥 버전

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

맨티스BT

맨티스BT

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

SublimeText3 Mac 버전

SublimeText3 Mac 버전

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

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

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

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구