-
Notifications
You must be signed in to change notification settings - Fork 0
/
filefreName.php
50 lines (46 loc) · 1.29 KB
/
filefreName.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
//利用PHP目录和文件函数遍历用户给出目录的所有的文件和文件夹,修改文件名称
// function frenName($dirname) {
// if (!is_dir($dirname)) {
// echo '不是一个有效的目录!';
// return 0;
// }
// $handle = opendir($dirname);
// while (($fn = readdir($handle)) !== false ) {
// if ( $fn!='.' && $fn!= '..' ) {
// $curDir = $dirname.'/'.$fn;
// if (is_dir($curDir)) {
// fRename($curDir);
// } else {
// $path = pathinfo($curDir);
// $newname = $path['dirname'].'/'.rand(0, 100).'.'.$path['extension'];
// rename($curDir, $newname);
// echo $curDir.'---rrrrrrrrr---'.$newname.'<br/>';
// }
// }
// }
// }
$path = "/chat/emoticons/images";
fRename($path);
function fRename($dirname){
if(!is_dir($dirname)){
echo "{$dirname}不是一个有效的目录!";
exit();
}
$handle = opendir($dirname);
while(($fn = readdir($handle))!==false){
echo "{sdfasdfasdfasdf}";
if($fn!='.'&&$fn!='..'){
$curDir = $dirname.'/'.$fn;
if(is_dir($curDir)){
fRename($curDir);
}
else{
$path = pathinfo($curDir);
$newname = $path['dirname'].'/'.rand(0,100).'.'.$path['extension'];
rename($curDir,$newname);
echo $curDir.'---'.$newname."<br>";
}
}
}
}