将以下代码转成python的代码 private static void fileRename(String newFileName, String folder) { File file = new File(folder); System.out.println("Reading this " + file.toString()); if (file.isDirectory()) { File[] files = file.listFiles(); List<File> filelist = Arrays.asList(files); filelist.forEach(f -> { System.out.println(f.getAbsolutePath()); String newName = folder + newFileName; System.out.println(newName); boolean isRenamed = f.renameTo(new File(newName)); if (isRenamed) System.out.println(String.format("Renamed this file %s to %s", f.getName(), newName)); else System.out.println(String.format("%s file is not renamed to %s", f.getName(), newName)); }); }
时间: 2023-02-11 15:24:55 浏览: 141
用python语言进行文件重命名
```python
import os
def file_rename(new_file_name: str, folder: str):
file = os.path.join(folder)
print("Reading this " + file)
if os.path.isdir(file):
files = os.listdir(file)
for f in files:
print(os.path.abspath(f))
new_name = os.path.join(folder, new_file_name)
print(new_name)
is_renamed = os.rename(f, new_name)
if is_renamed:
print(f"Renamed this file {f} to {new_name}")
else:
print(f"{f} file is not renamed to {new_name}")
```
阅读全文