How do I split filenames from paths using python?

Posted by Rasputin Jones on Stack Overflow See other posts from Stack Overflow or by Rasputin Jones
Published on 2010-05-31T01:04:13Z Indexed on 2010/05/31 1:12 UTC
Read the original article Hit count: 288

Filed under:
|

I have a list of files that look like this:

Input

/foo/bar/baz/d4dc7c496100e8ce0166e84699b4e267fe652faeb070db18c76669d1c6f69f92.mp4
/foo/baz/bar/60d24a24f19a6b6c1c4734e0f288720c9ce429bc41c2620d32e01e934bfcd344.mp4
/bar/baz/foo/cd53fe086717a9f6fecb1d0567f6d76e93c48d7790c55e83e83dd1c43251e40e.mp4

And I would like to split out the filenames from the path while retaining both.

Output

['/foo/bar/baz/', 'd4dc7c496100e8ce0166e84699b4e267fe652faeb070db18c76669d1c6f69f92.mp4']
['/foo/baz/bar/', '60d24a24f19a6b6c1c4734e0f288720c9ce429bc41c2620d32e01e934bfcd344.mp4']
['/bar/baz/foo', 'd53fe086717a9f6fecb1d0567f6d76e93c48d7790c55e83e83dd1c43251e40e.mp4']

How would one go about this?

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about regex