Full splitting of a file's pathname

Simon Forman rogue_pedro at yahoo.com
Mon Jul 10 21:04:34 EDT 2006


BartlebyScrivener wrote:
> I don't know if it's "standard," but why not just:
>
> dir = './foo/bar/moo/lar/myfile.txt'
> dir.split('/')
>
> ['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt']
>
> rd

There's also os.path.sep, from the docs: "The character used by the
operating system to separate pathname components."
But a recursive function like the one Iain King posted is likely the
best way to go.

~Simon




More information about the Python-list mailing list