linux - To print a particular folder name in python? -
i've made script in python scans folders , sub-folders , prints folders , subfolders begin word hello.
now need implement change should able print folder has word hello. word hihello or abchelloxyz. folder must printed. guess grep command needs used.
import os if os.path.isdir('/'): root, dirs, files in os.walk('/'): name in dirs: if name.startswith(("hello")): print ("\n\nfile name: "+ name) name = os.path.abspath(os.path.join(root, name) ) print ("path :"+name)
you can test if 'hello'
substring in dirname
using 'hello' in dirname
:
in [1]: dirname = 'hihello' in [3]: 'hello' in dirname out[3]: true in [4]: dirname.startswith('hello') out[4]: false
Comments
Post a Comment