[Python] Where file search utility

This utility searches all the paths in a semi-colon delimited environment variable list for files matching a given filespec. By default, PATH is used for the enviroment. For example, on my computer

C:\>where note*.exe


"""Searches a path for a specified file.

__author__ = "Bill McNeill <billmcn@speakeasy.net>"
__version__ = "1.0"

import sys
import os
import os.path
import glob

def help():
        print """\
where (Environment) Filespec

Searches the paths specified in Environment for all files matching Filespec.
If Environment is not specified, the system PATH is used.\

if len(sys.argv) == 3:
        paths = os.environ[sys.argv[1]]
        file = sys.argv[2]
elif len(sys.argv) == 2:
        paths = os.environ["PATH"]
        file = sys.argv[1]

for path in paths.split(";"):
        for match in glob.glob(os.path.join(path, file)):
                print match

가장 많이 본 글