How to check If a file isn't exists in folder and subfolders using python 2.7 -
i try find folders missing file name "kavi*" inside them. folders spread in 1 big folder divided lot of sub folders , sub sub folders. started code don't know how proceed:
import arcpy,fnmatch,os rootpath = r"d:\projects\road57\gis\layers\taba\taba-mmi" pattern = 'kavi*.shp' root, dirs, files in os.walk(rootpath): filename in fnmatch.filter(files, pattern): print(os.path.join(root, filename))
the out put is:
d:\projects\road57\gis\layers\taba\taba-mmi\8233\4022502\kavim kchulim.shp d:\projects\road57\gis\layers\taba\taba-mmi\8233\4022950\kavim kchulim.shp d:\projects\road57\gis\layers\taba\taba-mmi\8233\4050004\kavim_kchulim.shp d:\projects\road57\gis\layers\taba\taba-mmi\9887\4050012\kavim_kchulim.shp d:\projects\road57\gis\layers\taba\taba-mmi\9889\4050025\kavim_kchulim.shp d:\projects\road57\gis\layers\taba\taba-mmi\9900\4050040\kavim_kchulim.shp >>>
this print folders "kavi*" file. need output folders don't include "kavi*" file
your os.walk()
returns current path root
and, when directory, files in files
. if none of files
match pattern, should print out current root
.
for root, dirs, files in os.walk(rootpath): if files != [] , fnmatch.filter(files, pattern) == []: print root
Comments
Post a Comment