Skip to content

Instantly share code, notes, and snippets.

@grundic
Created October 11, 2014 12:33
Show Gist options
  • Save grundic/150b3849c94e350c51c4 to your computer and use it in GitHub Desktop.
Save grundic/150b3849c94e350c51c4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
if __name__ == '__main__':
path = '/some/very/long/path/with/data/inside/hello.txt'
subpaths = list()
splitted = path.split('/')
for index, p in enumerate(splitted):
subpath = '/'.join(splitted[:index])
if subpath:
subpaths.append(subpath)
for p in subpaths:
print p
================================
output
/some
/some/very
/some/very/long
/some/very/long/path
/some/very/long/path/with
/some/very/long/path/with/data
/some/very/long/path/with/data/inside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment