<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
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/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Autarchy of the Private Cave &#187; folder</title> <atom:link href="https://bogdan.org.ua/tags/folder/feed" rel="self" type="application/rss+xml" /><link>https://bogdan.org.ua</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Wed, 28 Dec 2022 16:09:04 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>https://wordpress.org/?v=3.8.27</generator> <item><title>Linux console/CLI/ncurses samba shared folders browsing</title><link>https://bogdan.org.ua/2009/04/16/linux-console-cli-ncurses-samba-shared-folder-browser-browsing.html</link> <comments>https://bogdan.org.ua/2009/04/16/linux-console-cli-ncurses-samba-shared-folder-browser-browsing.html#comments</comments> <pubDate>Thu, 16 Apr 2009 12:22:37 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[cifs]]></category> <category><![CDATA[CLI]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[folder]]></category> <category><![CDATA[linux]]></category> <category><![CDATA[samba]]></category> <category><![CDATA[shared]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=665</guid> <description><![CDATA[Connecting remotely via ssh to my Debian box at work, I needed to mount a CIFS (samba) share, but didn&#8217;t remember server name (or IP) and share name. At least two convenient utilities are available in Debian Lenny for non-X Samba browsing. smbtree (part of smbclient package) will list all visible workgroups, their servers, and [&#8230;]]]></description> <content:encoded><![CDATA[<p>Connecting remotely via ssh to my Debian box at work, I needed to mount a CIFS (samba) share, but didn&#8217;t remember server name (or IP) and share name.</p><p>At least two convenient utilities are available in Debian Lenny for non-X Samba browsing.</p><p><strong>smbtree</strong> (part of <strong>smbclient</strong> package) will list all visible workgroups, their servers, and share names of those servers &#8211; including &#8220;hidden&#8221; shares like C$, IPC$, ADMIN$, print$. Very handy and greppable!</p><p><strong>samba-commander</strong> (<strong>smbc</strong> package) is a ncurses samba browser with &#8220;find file&#8221; functionality.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F04%2F16%2Flinux-console-cli-ncurses-samba-shared-folder-browser-browsing.html&amp;linkname=Linux%20console%2FCLI%2Fncurses%20samba%20shared%20folders%20browsing" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F04%2F16%2Flinux-console-cli-ncurses-samba-shared-folder-browser-browsing.html&amp;linkname=Linux%20console%2FCLI%2Fncurses%20samba%20shared%20folders%20browsing" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F04%2F16%2Flinux-console-cli-ncurses-samba-shared-folder-browser-browsing.html&amp;linkname=Linux%20console%2FCLI%2Fncurses%20samba%20shared%20folders%20browsing" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F04%2F16%2Flinux-console-cli-ncurses-samba-shared-folder-browser-browsing.html&amp;linkname=Linux%20console%2FCLI%2Fncurses%20samba%20shared%20folders%20browsing" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2009%2F04%2F16%2Flinux-console-cli-ncurses-samba-shared-folder-browser-browsing.html&amp;linkname=Linux%20console%2FCLI%2Fncurses%20samba%20shared%20folders%20browsing" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2009%2F04%2F16%2Flinux-console-cli-ncurses-samba-shared-folder-browser-browsing.html&#038;title=Linux%20console%2FCLI%2Fncurses%20samba%20shared%20folders%20browsing" data-a2a-url="https://bogdan.org.ua/2009/04/16/linux-console-cli-ncurses-samba-shared-folder-browser-browsing.html" data-a2a-title="Linux console/CLI/ncurses samba shared folders browsing"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2009/04/16/linux-console-cli-ncurses-samba-shared-folder-browser-browsing.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Python: iterate (and read) all files in a directory (folder)</title><link>https://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html</link> <comments>https://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html#comments</comments> <pubDate>Sun, 12 Aug 2007 11:33:57 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[directory]]></category> <category><![CDATA[files]]></category> <category><![CDATA[folder]]></category> <category><![CDATA[glob]]></category> <category><![CDATA[iterate]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html</guid> <description><![CDATA[To iterate through all the files within the specified directory (folder), with ability to use wildcards (*, ?, and [ ]-style ranges), use the following code snippet: import os import glob &#160; path = 'sequences/' for infile in glob.glob&#40; os.path.join&#40;path, '*.fasta'&#41; &#41;: &#160; &#160; print &#34;current file is: &#34; + infile If you do not [&#8230;]]]></description> <content:encoded><![CDATA[<p>To iterate through all the files within the specified directory (folder), with ability to use wildcards (*, ?, and [ ]-style ranges), use the following code snippet:<br
/> <span
id="more-200"></span></p><div
id="ig-sh-1" class="syntax_hilite"><div
class="code"><ol
class="python" style="font-family:monospace;"><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff7700;font-weight:bold;">import</span> <span
style="color: #dc143c;">os</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff7700;font-weight:bold;">import</span> <span
style="color: #dc143c;">glob</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">path <span
style="color: #66cc66;">=</span> <span
style="color: #483d8b;">'sequences/'</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff7700;font-weight:bold;">for</span> infile <span
style="color: #ff7700;font-weight:bold;">in</span> <span
style="color: #dc143c;">glob</span>.<span
style="color: #dc143c;">glob</span><span
style="color: black;">&#40;</span> <span
style="color: #dc143c;">os</span>.<span
style="color: black;">path</span>.<span
style="color: black;">join</span><span
style="color: black;">&#40;</span>path<span
style="color: #66cc66;">,</span> <span
style="color: #483d8b;">'*.fasta'</span><span
style="color: black;">&#41;</span> <span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">&quot;current file is: &quot;</span> + infile</div></li></ol></div></div><p>If you do not need wildcards, then there is a simpler way to list all items in a directory:</p><div
id="ig-sh-2" class="syntax_hilite"><div
class="code"><ol
class="python" style="font-family:monospace;"><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff7700;font-weight:bold;">import</span> <span
style="color: #dc143c;">os</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">path <span
style="color: #66cc66;">=</span> <span
style="color: #483d8b;">'sequences/'</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">listing <span
style="color: #66cc66;">=</span> <span
style="color: #dc143c;">os</span>.<span
style="color: black;">listdir</span><span
style="color: black;">&#40;</span>path<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span
style="color: #ff7700;font-weight:bold;">for</span> infile <span
style="color: #ff7700;font-weight:bold;">in</span> listing:</div></li><li
style="font-weight: normal; vertical-align:top;"><div
style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">&quot;current file is: &quot;</span> + infile</div></li></ol></div></div><p><strong>print</strong> was promoted from a statement to a <a
href="http://www.harshj.com/2008/12/09/the-new-print-function-in-python-3/">function</a> in Python 3 (use <strong>print(infile)</strong> instead of <strong>print infile</strong>).</p><p>One should use &#8216;os.path.join()&#8217; part to make the script cross-platform-portable (different OS use different path separators, and hard-coding path separator would stop the script from executing under a different OS).</p><p><a
href="http://docs.python.org/library/glob.html">Python docs</a> mention that there is also iglob(), which is an iterator and thus working on directories with way too many files it will save memory by returning only single result per iteration, and not the whole list of files &#8211; as glob() does.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F08%2F12%2Fpython-iterate-and-read-all-files-in-a-directory-folder.html&amp;linkname=Python%3A%20iterate%20%28and%20read%29%20all%20files%20in%20a%20directory%20%28folder%29" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F08%2F12%2Fpython-iterate-and-read-all-files-in-a-directory-folder.html&amp;linkname=Python%3A%20iterate%20%28and%20read%29%20all%20files%20in%20a%20directory%20%28folder%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F08%2F12%2Fpython-iterate-and-read-all-files-in-a-directory-folder.html&amp;linkname=Python%3A%20iterate%20%28and%20read%29%20all%20files%20in%20a%20directory%20%28folder%29" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F08%2F12%2Fpython-iterate-and-read-all-files-in-a-directory-folder.html&amp;linkname=Python%3A%20iterate%20%28and%20read%29%20all%20files%20in%20a%20directory%20%28folder%29" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2007%2F08%2F12%2Fpython-iterate-and-read-all-files-in-a-directory-folder.html&amp;linkname=Python%3A%20iterate%20%28and%20read%29%20all%20files%20in%20a%20directory%20%28folder%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2007%2F08%2F12%2Fpython-iterate-and-read-all-files-in-a-directory-folder.html&#038;title=Python%3A%20iterate%20%28and%20read%29%20all%20files%20in%20a%20directory%20%28folder%29" data-a2a-url="https://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html" data-a2a-title="Python: iterate (and read) all files in a directory (folder)"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2007/08/12/python-iterate-and-read-all-files-in-a-directory-folder.html/feed</wfw:commentRss> <slash:comments>39</slash:comments> </item> </channel> </rss>