python - How to find the path of a changing directory name? -


i want access following path on ubuntu in python code:

~/.mozilla/firefox/dh4ytbdj.default/bookmarkbackups  

which contains firefox bookmarks

the problem part before '.default' different every user , machine. there way can specify general path directory , make python access , retrieve desired file?

and possible implement '~' in python code access current user's home?

>>> import os >>> os.path.expanduser('~/.mozilla/firefox/dh4ytbdj.default/bookmarkbackups') '/home/username/.mozilla/firefox/dh4ytbdj.default/bookmarkbackups' 

for system-wide access of personal firefox directories (with sufficient rights) try:

>>> import glob >>> glob.glob('/home/*/.mozilla/firefox/*.default/bookmarkbackups') 

as @nedbatchelder noted, can combined 1 command:

import os, glob next(glob.iglob(os.path.expanduser('~/.mozilla/firefox/*.default/bookmarkbackups'))) 

which returns 1 (if existing) path.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -