<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: walk code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 15:43:12 GMT</pubDate>
    <description>DZone Snippets: walk code</description>
    <item>
      <title>Comparing path.py with os.path</title>
      <link>http://snippets.dzone.com/posts/show/1463</link>
      <description>Taken from Simon Willson's &lt;a href=http://simon.incutio.com/archive/2003/01/22/pythonPathModule&gt;blog post&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# with os.path.walk&lt;br /&gt;def delete_backups(arg, dirname, names):&lt;br /&gt;    for name in names:&lt;br /&gt;        if name.endswith('~'):&lt;br /&gt;            os.remove(os.path.join(dirname, name))&lt;br /&gt;&lt;br /&gt;os.path.walk(os.environ['HOME'], delete_backups, None)&lt;br /&gt;&lt;br /&gt;# with os.path, if (like me) you can never remember how os.path.walk works&lt;br /&gt;def walk_tree_delete_backups(dir):&lt;br /&gt;    for name in os.listdir(dir):&lt;br /&gt;        path = os.path.join(dir, name)&lt;br /&gt;        if os.path.isdir(path):&lt;br /&gt;            walk_tree_delete_backups(path)&lt;br /&gt;        elif name.endswith('~'):&lt;br /&gt;            os.remove(path)&lt;br /&gt;&lt;br /&gt;walk_tree_delete_backups(os.environ['HOME'])&lt;br /&gt;&lt;br /&gt;# with path&lt;br /&gt;dir = path(os.environ['HOME'])&lt;br /&gt;for f in dir.walk():&lt;br /&gt;    if f.isfile() and f.endswith('~'):&lt;br /&gt;        os.remove(f)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 12 Feb 2006 20:08:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1463</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
