次のようなファイル パスを取得できる Python 関数を書きたいと思います。
/abs/path/to/my/file/file.txt
3 つの文字列変数を返します。
/abs
- ルート ディレクトリと、パス内の「最上位」ディレクトリfile
- パスの「一番下」のディレクトリ。の親file.txt
path/to/my
- パスの最上位ディレクトリと最下位ディレクトリの間のすべて
したがって、次の擬似コードを使用します。
def extract_path_segments(file):
absPath = get_abs_path(file)
top = substring(absPath, 0, str_post(absPath, "/", FIRST))
bottom = substring(absPath, 0, str_post(absPath, "/", LAST))
middle = str_diff(absPath, top, bottom)
return (top, middle, bottom)
ここで助けてくれてありがとう!