Created
March 4, 2020 20:07
-
-
Save JefferyW/8ce5da892f89e1c1acb4988e96037e65 to your computer and use it in GitHub Desktop.
Python os operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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