python Programming Glossary: os.path.isdir
How to generate an html directory list using Python http://stackoverflow.com/questions/10961378/how-to-generate-an-html-directory-list-using-python errors else for name in lst fn os.path.join path name if os.path.isdir fn tree 'children' .append make_tree fn else tree 'children'..
How to list only top level directories in Python? http://stackoverflow.com/questions/141291/how-to-list-only-top-level-directories-in-python share improve this question Filter the result using os.path.isdir and use os.path.join to get the real path name for name in os.listdir.. to get the real path name for name in os.listdir thedir if os.path.isdir os.path.join thedir name 'ctypes' 'distutils' 'encodings' 'lib..
How to use PIL to resize and apply rotation EXIF information to the file? http://stackoverflow.com/questions/1606587/how-to-use-pil-to-resize-and-apply-rotation-exif-information-to-the-file parent directory ies does not exist make them as well if os.path.isdir newdir pass elif os.path.isfile newdir raise OSError a file.. newdir else head tail os.path.split newdir if head and not os.path.isdir head _mkdir head if tail os.mkdir newdir if len sys.argv 3 print..
How do I copy an entire directory of files into an existing directory using Python? http://stackoverflow.com/questions/1868714/how-do-i-copy-an-entire-directory-of-files-into-an-existing-directory-using-pyth src s os.path.join src item d os.path.join dst item if os.path.isdir s shutil.copytree s d symlinks ignore else shutil.copy2 s d..
os.walk() python: xml representation of a directory structure, recursion http://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion use a recursive function that uses os.listdir os.path.join os.path.isdir etc. import os from xml.sax.saxutils import escape as xml_escape.. item in os.listdir path itempath os.path.join path item if os.path.isdir itempath dirs.append item elif os.path.isfile itempath files.append.. item in os.listdir path itempath os.path.join path item if os.path.isdir itempath result ' n'.join ' ' line for line in DirAsLessXML..
Return a list of imported Python modules used in a script? http://stackoverflow.com/questions/2572582/return-a-list-of-imported-python-modules-used-in-a-script r d os.path.abspath startPath if os.path.exists d and os.path.isdir d for root dirs files in os.walk d for f in files n ext os.path.splitext..
How do I zip the contents of a folder using python (version 2.5)? http://stackoverflow.com/questions/296499/how-do-i-zip-the-contents-of-a-folder-using-python-version-2-5 import os def zipdir basedir archivename assert os.path.isdir basedir with closing ZipFile archivename w ZIP_DEFLATED as z..
Adding folders to a zip file using python http://stackoverflow.com/questions/458436/adding-folders-to-a-zip-file-using-python file os.path.basename file zipfile.ZIP_DEFLATED elif os.path.isdir file addFolderToZip myZipFile file def createZipFile filename..
Filtering os.walk() dirs and files http://stackoverflow.com/questions/5141437/filtering-os-walk-dirs-and-files for path in paths append None for include in includes if os.path.isdir path append True break if fnmatch.fnmatch path include append.. include append True break for exclude in excludes if os.path.isdir path and path exclude append False break if fnmatch.fnmatch..
Tab completion in Python's raw_input() http://stackoverflow.com/questions/5637124/tab-completion-in-pythons-raw-input for name in os.listdir root path os.path.join root name if os.path.isdir path name os.sep res.append name return res def _complete_path.. to a single directory so return list of files below it if os.path.isdir path return os.path.join path p for p in self._listdir path..
mkdir -p functionality in python http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python OSError as exc # Python 2.5 if exc.errno errno.EEXIST and os.path.isdir path pass else raise Update For Python 3.2 os.makedirs has an..
IronPython: EXE compiled using pyc.py cannot import module “os” http://stackoverflow.com/questions/6195781/ironpython-exe-compiled-using-pyc-py-cannot-import-module-os a filename fullname os.path.join self.directory file if os.path.isdir fullname and not os.path.islink fullname and fullname 4 '.svn'..
Directory Walker for Python http://stackoverflow.com/questions/775231/directory-walker-for-python a filename fullname os.path.join self.directory file if os.path.isdir fullname and not os.path.islink fullname self.stack.append..
Getting a list of all subdirectories in the current directory http://stackoverflow.com/questions/973473/getting-a-list-of-all-subdirectories-in-the-current-directory the other solutions already posted using os.listdir and os.path.isdir including those at get all of the immediate subdirectories in..
|