Popular recipes tagged "paths" but not "normalization"http://code.activestate.com/recipes/tags/paths-normalization/2010-07-09T19:10:59-07:00ActiveState Code Recipesfile path generator from path patterns (Python) 2010-07-09T19:10:59-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577230-file-path-generator-from-path-patterns/ <p style="color: grey"> Python recipe 577230 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/paths/">paths</a>, <a href="/recipes/tags/walk/">walk</a>). Revision 4. </p> <p>Provides a <code>_paths_from_path_patterns</code> that will generate a list of paths from a list of path patterns. A "path pattern" can include glob chars. By default it generates a recursive listing of file paths, but: recursion can be turned off, file and/or dir paths can be listed. It supports a list of glob exclusions or inclusions.</p> <p>This function makes it easy to implement typical "-r|--recursive" and "-x|--exclude" options for command-line scripts that work on given file paths. See <a href="#block-1">example usages below</a>.</p> <p>Note: I use a leading <code>_</code> on function names because my typical usage of my recipes is as re-usable <em>internal</em> functions in Python modules.</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>