Php batch modify file name programs. Provides two php code that uses traversal to modify file names in batches. if you need it, refer to it. Copy the following code for an instance? Php uses the PHP directory and file function to provide two php code that uses traversal to modify file names in batches. if you need it, refer to it.
Instance 1
| The code is as follows: |
|
// Use the PHP directory and file function to traverse all the files and folders in the user's given directory and modify the file name
Function fRename ($ dirname ){
If (! Is_dir ($ dirname )){
Echo "{$ dirname} is not a valid directory! ";
Exit ();
}
$ 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. '---'. $ newname ."
";
}
}
}
}
// Give a directory name to call the function
FRename ('Pl ');
?> |
Instance 2
| The code is as follows: |
|
|
$ Dir = './';
If ($ dh = opendir ($ dir )){
While ($ file = readdir ($ dh ))! = False ){
If ($ file = "." | $ file = "..") continue;
If (filetype ($ dir. $ file) = 'file ')
{
$ Newfile = str_replace ('[1]', '', $ file );
Rename ($ dir. $ file, $ dir. $ newfile );
}
}
Closedir ($ dh );
} |
Bytes. The sample code is as follows? Php // use the PHP directory and file function again...