Using Python, how does one parse/access files with Linux-specific features, like "~/.mozilla/firefox/*.default"
? I've tried this, but it doesn't work.
Thanks
Using Python, how does one parse/access files with Linux-specific features, like "~/.mozilla/firefox/*.default"
? I've tried this, but it doesn't work.
Thanks
~
is expanded by the shell and not a real path. As such you have to navigate there manually.
import os
homeDir = os.environ['HOME']
f = open( homeDir + '/.mozilla/firefox/*.default' )
# ...
http://docs.python.org/library/os.html Gives a complete reference if you would like to change directory or give paths.
You can for example give relative paths and access specific files.
If you would like to execute commands then http://docs.python.org/library/commands.html provides nice wrappers for the os.popen() function
This
import glob, os
glob.glob(os.path.expanduser('~/.mozilla/firefox/*.default'))
will give you a list of all files ending in ".default" in the current user's ~/.mozilla/firefox
directory using os.path.expanduser to expand the ~
in the path and glob.glob to match the *.default
file pattern.
It's important to remember:
~
expands the home directory as per Poke's answer/
is the separator for linux / *nix directoriesecho *.*
will return back all files that match the asterisk dot asterisk (as per Will McCutcheon's answer!)Hope this helps, Best regards, Tom.