<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Python: iterate (and read) all files in a directory (folder)</title>
	<atom:link href="http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/feed" rel="self" type="application/rss+xml" />
	<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html</link>
	<description>Tiny bits of bioinformatics, [web-]programming etc</description>
	<lastBuildDate>Sun, 14 Mar 2010 08:55:31 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Dan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-103407</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Tue, 12 Jan 2010 02:43:47 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-103407</guid>
		<description>Ahh... My *.* as opposed to a * had it so it wasn&#039;t looking at folders, thus the problem. Thanks again!</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Ahh&#8230; My *.* as opposed to a * had it so it wasn&#8217;t looking at folders, thus the problem. Thanks again!<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-103404</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Mon, 11 Jan 2010 21:44:16 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-103404</guid>
		<description>Dan,

script below seems to work perfectly for me:
&lt;pre&gt;&lt;code&gt;
import os, glob

def scandirs(path):
    for currentFile in glob.glob( os.path.join(path, &#039;*&#039;) ):
        if os.path.isdir(currentFile):
            print &#039;got a directory: &#039; + currentFile
            scandirs(currentFile)
        print &quot;processing file: &quot; + currentFile

scandirs(&#039;Desktop&#039;)
&lt;/code&gt;&lt;/pre&gt;

Basically, I&#039;ve changed the &#039;*.*&#039; wildcard to just &#039;*&#039;.</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Dan,</p>
<p>script below seems to work perfectly for me:</p>
<pre><code>
import os, glob

def scandirs(path):
    for currentFile in glob.glob( os.path.join(path, '*') ):
        if os.path.isdir(currentFile):
            print 'got a directory: ' + currentFile
            scandirs(currentFile)
        print "processing file: " + currentFile

scandirs('Desktop')
</code></pre>
<p>Basically, I&#8217;ve changed the &#8216;*.*&#8217; wildcard to just &#8216;*&#8217;.<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-103402</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Mon, 11 Jan 2010 20:07:09 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-103402</guid>
		<description>Bogdan,

Thanks for the help. I&#039;m still not getting the code to look at the directories within the path. Here&#039;s my code, it still only looks at the files under the initial path.

&lt;pre&gt;&lt;code&gt;
def scandirs(path):
    for currentFile in glob.glob( os.path.join(path, &#039;*.*&#039;) ):
        if os.path.isdir(currentFile):
            scandirs(currentFile)
        print &quot;processing file: &quot; + currentFile
        

scandirs(&#039;XML/&#039;)
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Bogdan,</p>
<p>Thanks for the help. I&#8217;m still not getting the code to look at the directories within the path. Here&#8217;s my code, it still only looks at the files under the initial path.</p>
<pre><code>
def scandirs(path):
    for currentFile in glob.glob( os.path.join(path, '*.*') ):
        if os.path.isdir(currentFile):
            scandirs(currentFile)
        print "processing file: " + currentFile

scandirs('XML/')
</code></pre>
<p><!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-103321</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Sun, 03 Jan 2010 19:07:25 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-103321</guid>
		<description>Make that code into a function - e.g. scan_dirs(path) - and add a single line of code to it (pseudocode below):
&lt;code&gt;
if is_directory(infile): scan_dirs(infile)
&lt;/code&gt;

This will do exactly what you want.</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Make that code into a function &#8211; e.g. scan_dirs(path) &#8211; and add a single line of code to it (pseudocode below):<br />
<code><br />
if is_directory(infile): scan_dirs(infile)<br />
</code></p>
<p>This will do exactly what you want.<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-103320</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sun, 03 Jan 2010 18:14:11 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-103320</guid>
		<description>Is there a way to change this script so that it also runs through sub-directories under the given path name?</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Is there a way to change this script so that it also runs through sub-directories under the given path name?<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-102985</link>
		<dc:creator>Kris</dc:creator>
		<pubDate>Mon, 07 Dec 2009 00:11:09 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-102985</guid>
		<description>import os, glob
path = &#039;./&#039;
for infile in glob.glob( os.path.join(path, &#039;*.*&#039;) ):
    print(&quot;current file is: &quot; + infile)


#lists all files in directory script is in</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->import os, glob<br />
path = &#8216;./&#8217;<br />
for infile in glob.glob( os.path.join(path, &#8216;*.*&#8217;) ):<br />
    print(&#8220;current file is: &#8221; + infile)</p>
<p>#lists all files in directory script is in<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-102846</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Tue, 24 Nov 2009 01:38:22 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-102846</guid>
		<description>marvellous</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->marvellous<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ferralll</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-101297</link>
		<dc:creator>Ferralll</dc:creator>
		<pubDate>Mon, 18 May 2009 20:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-101297</guid>
		<description>Thankyou very much...
This was exactly what I was looking for!</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Thankyou very much&#8230;<br />
This was exactly what I was looking for!<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-101256</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Thu, 14 May 2009 01:52:37 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-101256</guid>
		<description>import os, glob

def dir(path):
    for infile in glob.glob( os.path.join(path) ):
        print &quot;current file is: &quot; + infile


path = dir(raw_input(&quot;Enter the path: &quot;))</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->import os, glob</p>
<p>def dir(path):<br />
    for infile in glob.glob( os.path.join(path) ):<br />
        print &#8220;current file is: &#8221; + infile</p>
<p>path = dir(raw_input(&#8220;Enter the path: &#8220;))<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-94523</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Tue, 23 Dec 2008 11:21:08 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-94523</guid>
		<description>Dt, thanks, I&#039;ve updated the code.</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Dt, thanks, I&#8217;ve updated the code.<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dt</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-94508</link>
		<dc:creator>Dt</dc:creator>
		<pubDate>Tue, 23 Dec 2008 09:38:45 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-94508</guid>
		<description>works just fine for me, only important change to the code that i had to make was turning print into a function because im using python 3.0, i also set it to read files with *all* extensions. 

import os, glob

path = &#039;insert your own path you lazy bastards &#039;

for infile in glob.glob( os.path.join(path, &#039;*.*&#039;) ):
       print(&quot;current file is: &quot; + infile)</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->works just fine for me, only important change to the code that i had to make was turning print into a function because im using python 3.0, i also set it to read files with *all* extensions. </p>
<p>import os, glob</p>
<p>path = &#8216;insert your own path you lazy bastards &#8216;</p>
<p>for infile in glob.glob( os.path.join(path, &#8216;*.*&#8217;) ):<br />
       print(&#8220;current file is: &#8221; + infile)<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-61984</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Sun, 23 Mar 2008 10:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-61984</guid>
		<description>it should. you might want to modify the example to suit your exact needs - this example assumes there is &#039;sequences&#039; folder with at least one .fasta file - if that&#039;s not true, then - evidently - you are not going to see this script work, be it windows or linux.</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->it should. you might want to modify the example to suit your exact needs &#8211; this example assumes there is &#8217;sequences&#8217; folder with at least one .fasta file &#8211; if that&#8217;s not true, then &#8211; evidently &#8211; you are not going to see this script work, be it windows or linux.<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seun</title>
		<link>http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/comment-page-1#comment-61892</link>
		<dc:creator>seun</dc:creator>
		<pubDate>Sat, 22 Mar 2008 18:13:36 +0000</pubDate>
		<guid isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comment-61892</guid>
		<description>This stuff isnt working on my windows system</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->This stuff isnt working on my windows system<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
</channel>
</rss>
