Find general directory of all linux files in python -
i want find general directory of linux files(not directory) in python. me?
example1:
['/home/tung/abc.txt', '/home/tung/xyz.txt'] -> general directory: '/home/tung' example2:
['/home/tung/abc.txt', '/home/tung/xyz.txt', '/home/user/123.txt'] -> general directory: '/home' example3:
['/home/tung/abc.txt', '/root/xyz.txt'] -> general directory: '/'
return longest path prefix (taken character-by-character) prefix of paths in list. if list empty, return empty string (''). note may return invalid paths because works character @ time.
alternatively, if using python 3.4+ (i guess part of answer more future), use pathlib and: purepaths.parts give
tuple giving access path’s various components.
convert tuples of different files lists, , find common list of prefixes list of lists.
Comments
Post a Comment