+ -
当前位置:首页 → 问答吧 → 如何删除多文件夹下重复的文件?

如何删除多文件夹下重复的文件?

时间:2011-05-24

来源:互联网

<?php
header('Content-Type: text/html; charset=gb2312');
function searchFiles( $srcPath = '', $dstFile = '*', $subDir = false ){
  static $files = array();
  if ( !empty( $srcPath ) ) $srcPath = rtrim( $srcPath, '/' ).'/';
  $file = glob( $srcPath.$dstFile );
  if ( !empty( $file ) ) $files = array_merge( $files, $file );
  if ( $subDir ){
  foreach( glob( $srcPath.'*', GLOB_ONLYDIR ) as $dir ){
  searchFiles( $dir, $dstFile, $subDir );
  }
  }
  return $files;
}
$files = searchFiles( './', '*.txt', true );
foreach( $files as $file ){
  if ( !is_writable( $file ) ) continue;
  $newname = preg_replace( '/(_\d*)*\.txt+$/i', '.txt', $file );
  if ( is_file( $newname ) ) unlink($file);//如果已经存在重命名后的文件,立即删除。
  rename( $file, $newname );//执行重命名
}
?> 
请问高手这样写对吗?

作者: lili19851121   发布时间: 2011-05-24

那位大仙指导一下,怎么样如何删除多文件夹下重复的文件?在php中

作者: lili19851121   发布时间: 2011-05-24