Top-rated recipes tagged "directory"http://code.activestate.com/recipes/tags/directory/top/2017-03-27T13:20:41-07:00ActiveState Code RecipesPDF 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> 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> 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> Directory Deleter (Python) 2011-07-27T15:23:29-07:00mJackhttp://code.activestate.com/recipes/users/4178791/http://code.activestate.com/recipes/577809-directory-deleter/ <p style="color: grey"> Python recipe 577809 by <a href="/recipes/users/4178791/">mJack</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/directory/">directory</a>). </p> <p>This small program lets a user delete a directory on their Windows system. Also good for learning from.</p> Getting 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> 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> 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> 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> 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> Ghoster - Windows program to create 0kb clone of folder or drive (Python) 2012-09-02T13:30:29-07:00commentator8http://code.activestate.com/recipes/users/4182761/http://code.activestate.com/recipes/578251-ghoster-windows-program-to-create-0kb-clone-of-fol/ <p style="color: grey"> Python recipe 578251 by <a href="/recipes/users/4182761/">commentator8</a> (<a href="/recipes/tags/clone/">clone</a>, <a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>A program that will create a "ghost" of a given directory or drive on windows systems (easily adaptable to unix etc) to a given destination. This will consist of a copy of all folders and files with only names and extensions retained, not size. This allows browsing of a remote drive or network location when offline.</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> Destroying Directories (Python) 2011-04-21T02:55:31-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577670-destroying-directories/ <p style="color: grey"> Python recipe 577670 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/recursion/">recursion</a>). </p> <p>When files and directories need to be securely deleted, there are many tools in existence that people can turn to for their needs. While there are many ways one might go about manually deleting files and removing directories, this recipe provides a sample implementation of what may be considered throughout the process. This destructive command line program takes the path to a directory as a command line argument and does its best to render it and its contents unrecoverable. There are much better and inclusive applications than this one, but those wishing to write their own utilities may take some inspiration from this recipe while writing their own tools.</p> <p>If there are any recommendation for this recipe or if anyone wishes to down-vote this recipe, please provide corrective criticism showing the the program's faults and give suggestions on how you would fix any problems that it might have.</p> user and root directory logfile (Python) 2011-03-22T10:00:49-07:00justin drakehttp://code.activestate.com/recipes/users/4177409/http://code.activestate.com/recipes/577619-user-and-root-directory-logfile/ <p style="color: grey"> Python recipe 577619 by <a href="/recipes/users/4177409/">justin drake</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/log/">log</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/user/">user</a>). </p> <p>script to retrieve time, current user, and root of directory output to spam.txt</p> <p>want to add more like windows version, bios info and other useful diagnostic information </p> <p>free to use and modify welcome any advice or corrections learning python hope this turns into a script to create a organized personal report of customer's pc</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> 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> 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> CGI Directory Contents (Python) 2012-07-02T22:38:31-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578183-cgi-directory-contents/ <p style="color: grey"> Python recipe 578183 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/old/">old</a>). </p> <p>CGI Directory Contents was a simple experiment meant to work similarly to the <code>os.listdir</code> function in Python. This is committed for archival to be run under Python 2.5 or later versions.</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> 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> 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>