Skip to content

Instantly share code, notes, and snippets.

@JefferyW
Created March 4, 2020 20:07
Show Gist options
  • Save JefferyW/8ce5da892f89e1c1acb4988e96037e65 to your computer and use it in GitHub Desktop.
Save JefferyW/8ce5da892f89e1c1acb4988e96037e65 to your computer and use it in GitHub Desktop.
Python os operation
# For searching the file which name contains specific string in folder and sub folder
def search(s,t,mainpath):
rootdir = mainpath
searchpath = np.zeros(0)
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
if filename.find(s) != -1 and filename.find(t) != -1:
searchpath = np.append(searchpath,
os.path.abspath(os.path.join(parent,filename)))
return searchpath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment