Answers the file name part of the path. >>> path2Name('/xxx/yyy/zzz/Agency_FB-Compressed.ufo') 'Agency_FB-Compressed.ufo' >>> path2Name('a/b/c') 'c' >>> path2Name('a/b/c/') 'Untitled' >>> path2Name('') 'Untitled' >>> path2Name(None) is None True
(path, default=None)
| 558 | return None |
| 559 | |
| 560 | def path2Name(path, default=None): |
| 561 | """Answers the file name part of the path. |
| 562 | |
| 563 | >>> path2Name('/xxx/yyy/zzz/Agency_FB-Compressed.ufo') |
| 564 | 'Agency_FB-Compressed.ufo' |
| 565 | >>> path2Name('a/b/c') |
| 566 | 'c' |
| 567 | >>> path2Name('a/b/c/') |
| 568 | 'Untitled' |
| 569 | >>> path2Name('') |
| 570 | 'Untitled' |
| 571 | >>> path2Name(None) is None |
| 572 | True |
| 573 | """ |
| 574 | if not default: |
| 575 | default = 'Untitled' |
| 576 | if path is None: |
| 577 | return None |
| 578 | if not path: # In case of an empty string or False, answer default. |
| 579 | return default |
| 580 | name = path.split('/')[-1] |
| 581 | if not name: # In case path ended with a slash |
| 582 | return default |
| 583 | return name |
| 584 | |
| 585 | def path2Dir(path): |
| 586 | """Answers the file name part of the path. |
no outgoing calls
no test coverage detected