Most viewed recipes tagged "directory"http://code.activestate.com/recipes/tags/directory/views/2017-03-27T13:20:41-07:00ActiveState Code RecipesGetting the SHA-1 (or MD5) hash of a directory (Python) 2009-12-06T19:02:40-08:00Stephen Akikihttp://code.activestate.com/recipes/users/4172143/http://code.activestate.com/recipes/576973-getting-the-sha-1-or-md5-hash-of-a-directory/ <p style="color: grey"> Python recipe 576973 by <a href="/recipes/users/4172143/">Stephen Akiki</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/getting/">getting</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/md5/">md5</a>, <a href="/recipes/tags/sha_1/">sha_1</a>, <a href="/recipes/tags/the/">the</a>). Revision 4. </p> <h5><a href="http://akiscode.com/articles/sha-1directoryhash.shtml" rel="nofollow">http://akiscode.com/articles/sha-1directoryhash.shtml</a></h5> <p>By definition a cryptographic hash is, "a deterministic procedure that takes an arbitrary block of data and returns a fixed-size bit string, the (cryptographic) hash value, such that an accidental or intentional change to the data will change the hash value". </p> <p>Usually these hashes are used on files to "fingerprint" them, but in order to do the same to a directory you have to do something like this: </p> PDF a Directory of Images using Reportlab (Python) 2009-04-12T08:35:10-07:00andrew.canithttp://code.activestate.com/recipes/users/4169843/http://code.activestate.com/recipes/576717-pdf-a-directory-of-images-using-reportlab/ <p style="color: grey"> Python recipe 576717 by <a href="/recipes/users/4169843/">andrew.canit</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/pdf/">pdf</a>). </p> <p>Walk through a directory PDFing Images</p> ChangeDirectory context manager (Python) 2009-01-24T12:41:53-08:00Christophe Simonishttp://code.activestate.com/recipes/users/4166953/http://code.activestate.com/recipes/576620-changedirectory-context-manager/ <p style="color: grey"> Python recipe 576620 by <a href="/recipes/users/4166953/">Christophe Simonis</a> (<a href="/recipes/tags/change/">change</a>, <a href="/recipes/tags/chdir/">chdir</a>, <a href="/recipes/tags/context_manager/">context_manager</a>, <a href="/recipes/tags/directory/">directory</a>). Revision 2. </p> <p>A context manager that handle a temporary change of the working directory</p> Find Duplicate Files (Python) 2014-10-12T21:14:05-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578950-find-duplicate-files/ <p style="color: grey"> Python recipe 578950 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/disk/">disk</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Finds duplicate files which have same size and same content in the same directory or two different directories.</p> Simple directory tree view generator (Python) 2012-03-09T09:02:21-08:00ajaymenon.khttp://code.activestate.com/recipes/users/4181225/http://code.activestate.com/recipes/578065-simple-directory-tree-view-generator/ <p style="color: grey"> Python recipe 578065 by <a href="/recipes/users/4181225/">ajaymenon.k</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/tree/">tree</a>). </p> <p>An extremely simple tree-view generator for a directory</p> Simple directory list command with filename wildcard support (Python) 2016-12-02T20:52:56-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580724-simple-directory-list-command-with-filename-wildca/ <p style="color: grey"> Python recipe 580724 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/filesystem/">filesystem</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utilities/">utilities</a>). </p> <p>This recipe shows a simple directory listing program. It can accept multiple command-line arguments specifying filenames. These filenames can include wildcard characters like * (asterisk) and ? (question mark), as is common in OS command shells like bash (Unix) and CMD (Windows). Tested on Windows but should work on Unix too, since it uses no OS-specific functions, or rather, it does use them, but that happens under the hood, within the libraries used.</p> Directory Walking File Renamer (Python) 2008-12-28T08:04:34-08:00mickey Hadickhttp://code.activestate.com/recipes/users/4168585/http://code.activestate.com/recipes/576597-directory-walking-file-renamer/ <p style="color: grey"> Python recipe 576597 by <a href="/recipes/users/4168585/">mickey Hadick</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/rename/">rename</a>). </p> <p>Walk through a list of directories and rename the files within those directories based on the directory name and an index value. Useful for managing photos when downloaded from a camera into directories based on the shooting date.</p> Directory Size (GUI) (Python) 2011-02-09T13:47:54-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577567-directory-size-gui/ <p style="color: grey"> Python recipe 577567 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/application/">application</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/sizeof/">sizeof</a>, <a href="/recipes/tags/tree/">tree</a>). Revision 2. </p> <p>Have you ever wanted to find out how much room a particular directory was taking up on your hard drive? A roommate of mine in college was having trouble keeping track of where his hard drive space is going, so the following program provided a solution that allows a brief overview of a directory's size along with all of its children. A tree view is created using tkinter and is populated with the directory's name, cumulative size, immediate total file size, and full path. The search button is disabled during a search, and the directory listing with its children is automatically updated.</p> Recursive find and replace in all files in directory with regex (Python) 2013-03-21T12:33:44-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/578312-recursive-find-and-replace-in-all-files-in-directo/ <p style="color: grey"> Python recipe 578312 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/regular_expressions/">regular_expressions</a>, <a href="/recipes/tags/replace/">replace</a>). </p> <p>Search and replace files recursively in a given directory. Accepts regular expressions as search and replacement patterns.</p> <p><strong>Example usage</strong>:</p> <pre class="prettyprint"><code>python find_replace_regex.py ".", "&lt;span[^&gt;]*&gt;", "&lt;div&gt;", "*.html" backup </code></pre> <p><strong>Note</strong>: On win32 the <code>&lt;</code> and <code>&gt;</code> symbols are interpreted by the shell as input/output redirection even when they are surrounded with single or double quotes, and therefore need to be escaped with the caret character <code>^</code>.</p> Shortcut Utility (Python) 2015-03-29T20:45:57-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579041-shortcut-utility/ <p style="color: grey"> Python recipe 579041 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/desktop/">desktop</a>, <a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/ui/">ui</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>I dislike filling my desktop with shortcut icons in Windows. This code enables creating shortcuts in a CSV file.</p> Directory Pruner 2 (Python) 2011-04-05T01:37:14-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577633-directory-pruner-2/ <p style="color: grey"> Python recipe 577633 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This program builds on work done in <a href="http://code.activestate.com/recipes/577632/">recipe 577632</a>, adds new options to the context menu, and experiments with threading the GUI. Directory Pruner 2 appear to work better on Windows 7 while Directory Pruner 1 (the non-threaded version) performs better on Windows XP. Those are the primary platforms on which the two programs have been tested. Please use these applications at your own risk.</p> <p>If you do not like something about this recipe and want to vote it down, please let everyone what you find fault with, how you would improve it, and an example of the code you would improve.</p> Dynamically create a dictionary of ascending paths (Python) 2012-12-03T22:50:47-08:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578354-dynamically-create-a-dictionary-of-ascending-paths/ <p style="color: grey"> Python recipe 578354 by <a href="/recipes/users/4181178/">Scott S-Allen</a> (<a href="/recipes/tags/bootstrap/">bootstrap</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/dynamic/">dynamic</a>, <a href="/recipes/tags/flexible/">flexible</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/portable/">portable</a>). </p> <p>Ripped from a more elaborate bootstrap script. A sequential set of parent-directories were required for environment variables and subsequent, portable. auto-discovery. </p> Directory Size (Console) (Python) 2011-02-09T13:29:56-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577566-directory-size-console/ <p style="color: grey"> Python recipe 577566 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/sizeof/">sizeof</a>, <a href="/recipes/tags/tree/">tree</a>). </p> <p>Have you ever wanted to find out how much room a particular directory was taking up on your hard drive? A roommate of mine in college was having trouble keeping track of where his hard drive space is going, so the following program provided a solution that allows a brief overview of a directory's size along with all of its children. A tree view is printed out in ASCII characters showing the relationship of each directory along with its size in a format easily readable to humans. The output can always be redirected to a text file if it needs to be saved for viewing later on.</p> dealing with directory paths with ~ (Python) 2010-06-16T23:17:20-07:00roopeshvhttp://code.activestate.com/recipes/users/4174204/http://code.activestate.com/recipes/577270-dealing-with-directory-paths-with/ <p style="color: grey"> Python recipe 577270 by <a href="/recipes/users/4174204/">roopeshv</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/expanding/">expanding</a>, <a href="/recipes/tags/paths/">paths</a>). Revision 2. </p> <p>Dealing with directory paths which start with <code>~</code> which are passed as paramaters, to <code>os</code> module functions.</p> <p>Here is what I think python doesn't do for me:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; import os # suppose my home = curdir = /home/rv &gt;&gt;&gt; os.path.abspath('.') '/home/rv' </code></pre> <p>Now if I want to go to folder <code>/home/rv/test</code> if there is no folder by name /home/rv/~/test/</p> <pre class="prettyprint"><code># This is what happens by default. &gt;&gt;&gt; os.path.abspath('~/test') '/home/rv/~/test' &gt;&gt;&gt; os.chdir('/home/rv/some/dir') # doesn't matter if the resulting path exists or not. &gt;&gt;&gt; os.path.abspath('~/test') 'home/rv/some/dir/~/test' </code></pre> <p>This would be more sensible I guess:</p> <pre class="prettyprint"><code># if /home/rv/~/test doesn't exist &gt;&gt;&gt; os.path.abspath('~/test') '/home/rv/test' </code></pre> File selector dialog in batch (Batch) 2017-03-27T13:20:41-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580665-file-selector-dialog-in-batch/ <p style="color: grey"> Batch recipe 580665 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/directory/">directory</a>). Revision 2. </p> <p>Runs mshta hidden to open a file dialog and get the path of the file selected. No parameters can be passed to the dialog. EDITED: I did a subroutine with the snippet</p> Directory Pruner 1 (Python) 2011-04-05T00:56:25-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577632-directory-pruner-1/ <p style="color: grey"> Python recipe 577632 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This program is an extension of <a href="http://code.activestate.com/recipes/577567/">recipe 577567</a> in that it not only allows one to find a directory's size but also remove files based on a context menu. The directory pruner has been used by my roommate to free up room on his hard drive and also by several friends that wished to remove games and other unnecessary program that were taking up their space. Right-click on found directories to review your options.</p> <p>If you wish to vote this recipe down, please post a comment at the bottom telling me how you would improve the utility.</p> Windows TREE Emulator (Python) 2010-03-08T12:57:10-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577091-windows-tree-emulator/ <p style="color: grey"> Python recipe 577091 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/listing/">listing</a>, <a href="/recipes/tags/tree/">tree</a>, <a href="/recipes/tags/utility/">utility</a>). Revision 2. </p> <p>Windows has a nice command line program capable of printing out a tree of the the folders, sub-folders, and possibly the files of a directory. The tool below mimics a behavioral subset of TREE, Microsoft's inspiring utility. This version is designed to output a similar tree and should be compatible on Windows, Linux, and Macintosh. In case it is not used correctly, a simple usage message will be printed (without notes on the optional "/F" switch). ASCII characters are used.</p> Directory Pruner 4 (Python) 2012-06-06T22:00:00-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578154-directory-pruner-4/ <p style="color: grey"> Python recipe 578154 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). Revision 2. </p> <p>Module providing GUI capability to prune any directory.</p> <p>The code presented in this module is for the purposes of: (1) ascertaining the space taken up by a directory, its files, its sub-directories, and its sub-files; (2) allowing for the removal of the sub-files, sub-directories, files, and directory found in the first purpose; (3) giving the user a GUI to accomplish said purposes in a convenient way that is easily accessible.</p> Recurse copy file (Python) 2010-12-09T09:52:36-08:00boussardhttp://code.activestate.com/recipes/users/4176187/http://code.activestate.com/recipes/577493-recurse-copy-file/ <p style="color: grey"> Python recipe 577493 by <a href="/recipes/users/4176187/">boussard</a> (<a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/recurse/">recurse</a>). </p> <p>Automate copy and paste file with erase the content of file if exists on destination directory. Like shutil.copytree but when dir is exists on destination tree , don't fail, just pass.</p> Directory Pruner 3 (Python) 2011-04-05T23:15:58-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577635-directory-pruner-3/ <p style="color: grey"> Python recipe 577635 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>After considering the monolithic design of <a href="http://code.activestate.com/recipes/577633/">recipe 577633</a> and deciding that it should be divided into several smaller modules, Directory Pruner 3 was written to take advantage of better abstraction methodologies. There are a total of twelve files in the project, and all of them except the first are contained within a directory called "Directory Pruner 3" such that they make up a package in Python. Like the other Directory Pruners, please use and configure this program at your own computer's risk.</p> <p>If you have any comments or wish to vote this recipe down, please provide an explanation as to what you find fault with in this program and also a solution that you would implement to fix the problem.</p>