【发布时间】:2020-10-23 11:35:21
【问题描述】:
我有一个根文件夹“topfolder”。在该文件夹中,我有多个子文件夹,“a”、“b”、“c”。 我想重命名这些子文件夹,以便它们与根文件夹连接,这样它们就变成了“topfolder_a”、“topfolder_b”等等。 用 Python 做这件事相对容易吗? 我想我几乎已经有了这段代码,但我无法得到最后一部分。
test_directory = "./topfolder"
for child in os.listdir(test_directory):
test_path = os.path.join(test_directory, child)
if os.path.isdir(test_path):
print(test_path)
【问题讨论】: