Advertisement
killerbng

Find File location - simple console file

Dec 7th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. import sys
  2. import os, fnmatch
  3.  
  4. def find(pattern, path):
  5.     result = []
  6.     for root, dirs, files in os.walk(path):
  7.         for name in files:
  8.             if fnmatch.fnmatch(name, pattern):
  9.                 result.append(os.path.join(root, name))
  10.     return result
  11.  
  12. a = find(sys.argv[1], sys.argv[2])
  13. print(str(a[0])) # Return the 1st result as string (change this if you want an array with multiple files)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement