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 - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -