特定のパスの親ディレクトリの名前を抽出する必要があります。これは次のようになります。c:\ stuff \ directory_i_need \ subdir \ file
"ファイル"の内容をdirectory_i_need
の名前(パスではない)を使用して変更しています。私は、その後、私のすべてのファイルのリストを与える機能...私はそれを行うことができますどのようにPythonでファイルパス(ディレクトリ)の一部を抽出します
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.
を作成していますか?
あなたはこの答えをチェックアウトする場合があります:http://stackoverflow.com/a/4580931/311220 – Acorn
上記のリンクは、私は理解してどのように役立ったかに私が間違ったことを修正してください。ありがとうございました。 – Thalia