For an example, I have my folder path as “/content/data/a/b/c/d/” How can I extract the “b” from this path?
Advertisement
Answer
If “b” never moves
file_path = "/content/data/a/b/c/d/" file_path.split('/')[4]
If it does move
file_path = "/content/data/a/b/c/d/" file_path[file_path.index("b")]