证书编号:PCTI00122
可以用linux命令行操作的 遍历目录 查找文件的代码
上一篇 /
下一篇 2007-07-11 08:29:13
/ 个人分类:代码
#!/usr/bin/php -q
<?php
/*
wangliang 2007-7-9
检查目录里图片的大小,不符合要求的写入./MistakePhoto.txt文件
*/
printf("Please provide your inquiries to the dir : "); //获得命令行下输入的目录路径
$dir = read_input(); //获得路径
printf("Please enter the size inquiries Photo (KB):"); //获得查询图片的大小
$filesize = read_input(); //获得判断图片的大小
if (is_dir($dir)) { //判断是否是目录
open_dir($dir);
}else{
echo "Directory does not exist!";
}
exit;
?>
<?
function read_input(){
$fp = fopen("/dev/stdin", "r");
$input = trim(fgets($fp, 1024));
fclose($fp);
return $input;
}
function open_dir($dir){
if (!is_dir($dir)){ //如果不是目录,return
return;
}
if ($dh = opendir($dir)) { //打开目录
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") { //去掉. and .. 目录
if(substr($file,-4)==".jpg" || substr($file,-4)==".JPG"){//判断图像类型是否为jpg
$filename=$dir."/".$file; //获得图片路径
open_file($filename);
}else{
$redir=$dir."/".$file; //重新定义一个dir为原dir+非jpg的文件名
open_dir($redir); //再次对目录进行递归,找出大于30k的图片
}
}
}
closedir($dh); //关闭目录
}
return;
}
function open_file($filename){
$filesize=$GLOBALS['filesize'];
$namesize=filesize($filename);
if($namesize > $filesize*1024){//判断图片大小
$fp=fopen("./MistakePhoto.csv","a+");
fwrite($fp,$filename.",".$namesize."\n"); //在打开的文件里写入
fclose($fp);
print_r ($filename.",".$namesize."\n"); //输出内容
}
return;
}
?>
相关阅读:
- 鼠标移动--变色的表格 (17too, 2007-3-15)
- 弹出提示的效果 (17too, 2007-3-15)
- 跳动的彩单 (17too, 2007-3-15)
- 自动最大话窗口 (17too, 2007-3-15)
- 设为首页,加为收藏,加入频道,启动outlook发信 (17too, 2007-3-15)
- 播放器 (17too, 2007-3-22)
- 一份上传图片的代码 (sharpnailn, 2007-6-17)
- PHP分页的讲解 (sharpnailn, 2007-6-18)
- 工作中接触过的PHP函数 (sharpnailn, 2007-7-03)
- php中header用法的范例 (sharpnailn, 2007-7-03)
导入论坛
收藏
分享给好友
管理
举报
TAG:
代码
linux命令行操作
遍历目录