我需要提取某个路径的父目录的名称。这就是它看起来的样子:c:\ stuff \ directory_i_need \ subdir \ file
。我正在用使用directory_i_need
。我创建了一个函数,它会给我一个所有文件的列表,然后:
for path in file_list:
#directory_name = os.path.dirname(path) # this is not what I need, that's why it is commented
directories, files = path.split('\\')
line_replace_add_directory = line_replace + directories
# this is what I want to add in the text, with the directory name at the end
# of the line.
我该怎么做?
相似问题