python - Finding a subdirectory that matches a file name -


i'm pretty new python, grateful help. i'm trying find subdirectory in specified directory matching title of specified zip file. there folder titled "1008" in "projects" folder i'm not sure what's wrong.

here code:

import os  zipfiles = r'c:\temp\python_test\zipped_files\1008.zip' prjfolder = r'c:\temp\python_test\projects' prjnum = os.path.basename(zipfiles) prjnum = os.path.splitext(prjnum) prjnum = prjnum[0] prjlist = os.walk(prjfolder).next()[1] prjlist = map(int, prjlist)  if prjnum in prjlist:     print "yes" else:     print "no" 

since know name of directory looking for, check see if exists

import os  zipfiles = r'c:\temp\python_test\zipped_files\1008.zip' prjfolder = r'c:\temp\python_test\projects' prjnum = os.path.basename(zipfiles) prjnum = os.path.splitext(prjnum) prjnum = prjnum[0] print os.path.isdir(os.path.join(prjfolder, prjnum)) 

Comments

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -