遍历重命名文件 //创建文件夹 遍历读取表单

Posted on 2008-05-21 16:07  flourish  阅读(320)  评论(0)    收藏  举报
写个小东西蛮好用的
$dir = "d:/www/1/";
$dirs = opendir($dir);
while($file = readdir($dirs))
{
  $filepath = $dir.$file;
  $a = is_dir($filepath);
  if(!$a)
  {
   $newfile = ereg_replace(",","_",$file);
   rename($filepath,$dir.$newfile);
   //rename($filepath,$dir."1_".$file);
  }
}

//创建文件夹
function makeDirectory($directoryName) {
$directoryName = str_replace("\\","/",$directoryName);
$dirNames = explode('/', $directoryName);
$total = count($dirNames) ;
$temp = '';
for($i=0; $i<$total; $i++) {
  $temp .= $dirNames[$i].'/';
  if (!is_dir($temp)) {
   $oldmask = umask(0);
   if (!mkdir($temp, 0777)) exit("不能建立目录 $temp");
   umask($oldmask);
  }
}
return true;
}
//删除文件夹以及文件夹下所有文件
function deldir($dir) {
  $dh=opendir($dir);
  while ($file=readdir($dh)) {
    if($file!="." && $file!="..") {
      $fullpath=$dir."/".$file;
      if(!is_dir($fullpath)) {
          unlink($fullpath);
      } else {
          deldir($fullpath);
      }
    }
  }
  closedir($dh);
  
  if(rmdir($dir)) {
    return true;
  } else {
    return false;
  }
}

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3