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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -