MCPcopy Create free account
hub / github.com/PageBot/PageBot / path2Name

Function path2Name

Lib/pagebot/toolbox/transformer.py:560–583  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

558 return None
559
560def 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
585def path2Dir(path):
586 """Answers the file name part of the path.

Callers 8

installFontMethod · 0.90
path2ScaledImagePathFunction · 0.85
path2FontNameFunction · 0.85
path2FamilyNameFunction · 0.85
path2FontIdFunction · 0.85
font2NameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected