Most viewed recipes tagged "os_walk"http://code.activestate.com/recipes/tags/os_walk/views/2013-05-28T07:21:28-07:00ActiveState Code RecipesCreate a nested dictionary from os.walk (Python)
2011-09-26T23:38:24-07:00Andrew Clarkhttp://code.activestate.com/recipes/users/4179419/http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/
<p style="color: grey">
Python
recipe 577879
by <a href="/recipes/users/4179419/">Andrew Clark</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/os_walk/">os_walk</a>).
Revision 2.
</p>
<p>Creates a nested dictionary that represents a folder structure. Here is an example of what the resulting dictionary might look like:</p>
<pre class="prettyprint"><code>{
"root": {
"folder2": {
"item2": None,
"item1": None
},
"folder1": {
"subfolder1": {
"item2": None,
"item1": None
},
"subfolder2": {
"item3": None
}
}
}
}
</code></pre>
Modified os.walk which return current directory depth (Python)
2009-11-06T16:16:42-08:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/576933-modified-oswalk-which-return-current-directory-dep/
<p style="color: grey">
Python
recipe 576933
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/directory_depth/">directory_depth</a>, <a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/relative_path/">relative_path</a>).
Revision 2.
</p>
<p>On some task I need to collect file names under specified directory with distance from it. Standard os.walk function do not return depth value.</p>
<p>One solution -- find function which will calculate relative distance from top directory to file.</p>
<p>Another [presented] solution -- modify os.walk so it returns depth level as fourth tuple's value.</p>
Tripwire policy file creator (Python)
2009-02-25T20:30:15-08:00Bill Sharerhttp://code.activestate.com/recipes/users/4168512/http://code.activestate.com/recipes/576670-tripwire-policy-file-creator/
<p style="color: grey">
Python
recipe 576670
by <a href="/recipes/users/4168512/">Bill Sharer</a>
(<a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tripwire/">tripwire</a>).
</p>
<p>gen_twpol.py is a script that can be used to generate a tripwire policy source (twpol.txt) for your system.</p>
<p>This script may be distributed under the terms of the Gnu Public License GPLv2 or later.</p>
<p>For more information on the open source version of tripwire see <a href="http://sourceforge.net/projects/tripwire/" rel="nofollow">http://sourceforge.net/projects/tripwire/</a></p>
<p>The tripwire source package usually ships with a an example twpol.txt file based on a RedHat Enterprise (RHEL)
distribution, typically an RHEL4 or RHEL5 version. It doesn't do much good to have this get parked by your Gentoo
ebuild (nor other distro packager) as all sorts of stuff in /boot, /lib/modules and other places will be
out of sync, differently named or just plain missing. In addition, your system may have extra stuff that isn't
present in the file but critical to the distro.</p>
lndir.py (short python version of the BSD/X11 lndir utility) (Python)
2013-05-28T07:21:28-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578535-lndirpy-short-python-version-of-the-bsdx11-lndir-u/
<p style="color: grey">
Python
recipe 578535
by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a>
(<a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/walk/">walk</a>).
Revision 2.
</p>
<p>This should be valid for Python 2.6 and up, including the 3.x series.</p>
Simultaneous topdown and bottomup variant of os.walk() (alt. title: "Delete .pyc files and empty directories recursively") (Python)
2010-04-21T20:16:09-07:00George Sakkishttp://code.activestate.com/recipes/users/2591466/http://code.activestate.com/recipes/577206-simultaneous-topdown-and-bottomup-variant-of-oswal/
<p style="color: grey">
Python
recipe 577206
by <a href="/recipes/users/2591466/">George Sakkis</a>
(<a href="/recipes/tags/os_walk/">os_walk</a>).
</p>
<p>The standard lib os.walk() function provides a topdown parameter that determines whether entries are yielded in a top-down or a bottom-up order. Sometimes though you may want each directory yielded twice; once before any of its children directories (and recursively their descendants) are yielded and once after they are all yielded. The walk2() function below does this by yielding 4-tuples; the first 3 elements are the same yielded by os.walk() and the 4th is True the first time (topdown) and False the second (bottomup).</p>
<p>An example is deleting all .pyc files and empty directories under some root dir, but excluding specific directories (e.g. VCS specific dirs). The exclusion check should be done topdown (we don't want to descend into any directory that must be excluded) but the check for empty directories has to be done bottom up, since a directory containing only .pyc files will be non-empty initially but empty after removing the files.</p>
Quickly add all dirs to sys.path if dir has .py file (Python)
2012-04-06T16:06:17-07:00Andrew Yurisichhttp://code.activestate.com/recipes/users/4180867/http://code.activestate.com/recipes/578097-quickly-add-all-dirs-to-syspath-if-dir-has-py-file/
<p style="color: grey">
Python
recipe 578097
by <a href="/recipes/users/4180867/">Andrew Yurisich</a>
(<a href="/recipes/tags/add/">add</a>, <a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/sys_path/">sys_path</a>).
Revision 2.
</p>
<p>Add all dirs under <code>folder</code> to sys.path if any .py files are found.
Use an abspath if you'd rather do it that way.</p>
<p>Uses the current working directory as the location of using.py.
Keep in mind that os.walk goes <em>all the way</em> down the directory tree.</p>
Local Secure (Perl)
2012-09-30T19:32:11-07:00Roger Mbiama Assogohttp://code.activestate.com/recipes/users/4182949/http://code.activestate.com/recipes/578274-local-secure/
<p style="color: grey">
Perl
recipe 578274
by <a href="/recipes/users/4182949/">Roger Mbiama Assogo</a>
(<a href="/recipes/tags/any/">any</a>, <a href="/recipes/tags/os_walk/">os_walk</a>).
</p>
<p>Debian LINUX os</p>