"IsADirectoryError: [Errno 21] Is a directory" when it is a file
"IsADirectoryError: [Errno 21] Is a directory" when it is a file
我尝试使用:
import os
my_path = [files for pth, dirs, files in os.walk(path)]
result_list = ['one', 'two', 'three']
for original_path, new_name in zip(my_path, result_list):
os.rename(original_path, 'path_to_save'.format(new_name))
我在哪里得到:
IsADirectoryError: [Errno 21] Is a directory: 'path-of-original-path' -> 'path-of-new-name'
但我可以确认 'original_path' 会像使用 os.path.isfile
returns True
.
一样指向一个文件
非常感谢任何帮助。
不知道为什么,但使用这个有效:
import shutil
shutil.move(original_path, 'path_to_save'.format(new_name))
我尝试使用:
import os
my_path = [files for pth, dirs, files in os.walk(path)]
result_list = ['one', 'two', 'three']
for original_path, new_name in zip(my_path, result_list):
os.rename(original_path, 'path_to_save'.format(new_name))
我在哪里得到:
IsADirectoryError: [Errno 21] Is a directory: 'path-of-original-path' -> 'path-of-new-name'
但我可以确认 'original_path' 会像使用 os.path.isfile
returns True
.
非常感谢任何帮助。
不知道为什么,但使用这个有效:
import shutil
shutil.move(original_path, 'path_to_save'.format(new_name))