function:
This function accepts a single parameter. $dirThe directory path containing the files to be batch-renamed. The function first uses glob() The function retrieves the file paths of all files within a specified directory. Then, the function uses a loop to iterate through all files and generates a new file name for each file. The format of the new file name is: $i.jpg,among $i An increasing numerical sequence number. If the new file name already exists, the file will be skipped, and the renaming operation will not be performed.
You can call this function using the following methods:
$dir = '/path/to/files';
renameFiles($dir);among,/path/to/files This specifies the directory path for batch renaming of files. After calling this function, it will rename all files within that directory, assigning new filenames starting from 1 and incrementing sequentially.