Plan 9 from Bell Labs’s /usr/web/sources/contrib/iainws/search.py

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


import os, sys

if __name__ == "__main__":
	directory_name = ""
	search_file = ""
	if len(sys.argv) != 3:
		print "Usage: python findfile.py <directory> <filename>"
		sys.exit(1)
	else:
		directory_name = sys.argv[1]
		search_file = sys.argv[2]
	results, matches = [],[]
	for dirpath, dirnames, filenames in os.walk(directory_name):
		for subdirectory in dirnames:
			os.path.join(dirpath, subdirectory)
		for filename in filenames:
			print dirpath + "/" + filename
			if filename == search_file:
				results.append(dirpath + "/" +filename)
				print dirpath + "/" + filename
			elif filename.startswith(search_file) or filename.endswith(search_file):
				matches.append(dirpath + "/" +  filename)

	if len(results) != 0:
		print "Found file(s): "
		for filepath in results:
			print filepath
	else:
		if len(matches) != 0:
			print "Found possibe matches:"
			for filepath in matches:
				print filepath

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].