<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: dir code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 12:49:48 GMT</pubDate>
    <description>DZone Snippets: dir code</description>
    <item>
      <title>perl grep dir and filename</title>
      <link>http://snippets.dzone.com/posts/show/5492</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;my($directory, $filename) = $text =~ m/(.*\/)(.*)$/;&lt;br /&gt;print "D=$directory, F=$filename\n&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 May 2008 20:03:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5492</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>Processing all files in a directory and its subdirectories ... revisited</title>
      <link>http://snippets.dzone.com/posts/show/5061</link>
      <description>&lt;code&gt;&lt;br /&gt;Dir['**/*.jpg'].foreach do |filename|&lt;br /&gt;  ... do anything with the filename&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jan 2008 09:32:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5061</guid>
      <author>arnoldu (Arnold Ude)</author>
    </item>
    <item>
      <title>Processing all files in a directory and its subdirectories ... revisited</title>
      <link>http://snippets.dzone.com/posts/show/5060</link>
      <description>// This code shows (once again) how to process all files in a directory and its subdirectories&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Dir['**/*.jpg'].foreach do |filename|&lt;br /&gt;  ... do anything with the filename&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jan 2008 09:31:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5060</guid>
      <author>arnoldu (Arnold Ude)</author>
    </item>
    <item>
      <title>Create a file directory listing in XML</title>
      <link>http://snippets.dzone.com/posts/show/4650</link>
      <description>// This code lists the filenames in the current directory which have a .xml extension, then saves them to an XML file.called 'dir.xml'.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class Xmldirectory&lt;br /&gt;  def initialize&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def create_directory_file&lt;br /&gt;    file = File.new('dir.xml','w')&lt;br /&gt;    doc = Document.new&lt;br /&gt;    doc.add_element('dir')&lt;br /&gt;&lt;br /&gt;    Dir["*.xml"].each do |x|&lt;br /&gt;      entry = Element.new('file')&lt;br /&gt;      entry.text = x&lt;br /&gt;      doc.root.add_element entry&lt;br /&gt;    end&lt;br /&gt;    file.puts doc&lt;br /&gt;    file.close&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 13 Oct 2007 15:58:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4650</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>C - command "ls"</title>
      <link>http://snippets.dzone.com/posts/show/2735</link>
      <description>&lt;code&gt;&lt;br /&gt;/*&lt;br /&gt; *&lt;br /&gt; * Esempio che scansiona una cartella stampando a video i file in essa&lt;br /&gt; * contenuti.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;#include &lt;dirent.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;	DIR *dir;&lt;br /&gt;	struct dirent *drent;&lt;br /&gt;&lt;br /&gt;	if(argc &lt; 2)&lt;br /&gt;	{&lt;br /&gt;		fprintf(stderr, "%s &lt;directory&gt;\n", argv[0]);&lt;br /&gt;		return EXIT_FAILURE;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	if((dir = opendir(argv[1])) == NULL)&lt;br /&gt;	{&lt;br /&gt;		fprintf(stderr, "Errore opendir()\n");&lt;br /&gt;		return EXIT_FAILURE;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	while((drent = readdir(dir)) != NULL)&lt;br /&gt;	{&lt;br /&gt;		fprintf(stdout, "--&gt; %s\n", drent-&gt;d_name);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	if(closedir(dir) &lt; 0)&lt;br /&gt;	{&lt;br /&gt;		fprintf(stderr, "Errore closedir()\n");&lt;br /&gt;		return EXIT_FAILURE;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Sep 2006 22:16:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2735</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Load file info for all files in a directory</title>
      <link>http://snippets.dzone.com/posts/show/1287</link>
      <description>&lt;code&gt;&lt;br /&gt;    load-dir: func [&lt;br /&gt;        "Load file info for all files in a directory."&lt;br /&gt;        path /local result orig-dir&lt;br /&gt;    ][&lt;br /&gt;        result: copy []&lt;br /&gt;        orig-dir: what-dir&lt;br /&gt;        change-dir dirize path&lt;br /&gt;        foreach file read %. [&lt;br /&gt;            repend result [&lt;br /&gt;                file&lt;br /&gt;                ;file: get-modes file 'full-path&lt;br /&gt;                make info? file  get-modes file get-modes file 'file-modes&lt;br /&gt;            ]&lt;br /&gt;            ; include # of files in sub-dirs?&lt;br /&gt;            ; include full-path?&lt;br /&gt;        ]&lt;br /&gt;        change-dir orig-dir&lt;br /&gt;        result&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 02:08:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1287</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Ensure a directory exists</title>
      <link>http://snippets.dzone.com/posts/show/1284</link>
      <description>&lt;code&gt;&lt;br /&gt;    ensure-dir-exists: func [dir] [attempt [make-dir/deep dir]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 02:06:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1284</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Copy a directory</title>
      <link>http://snippets.dzone.com/posts/show/1282</link>
      <description>&lt;code&gt;&lt;br /&gt;    copy-dir: func [source dest] [&lt;br /&gt;        if not exists? dest [make-dir/deep dest]&lt;br /&gt;        foreach file read source [&lt;br /&gt;            either find file "/" [&lt;br /&gt;                copy-dir source/:file dest/:file&lt;br /&gt;            ][&lt;br /&gt;                print file&lt;br /&gt;                write/binary dest/:file read/binary source/:file&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 02:05:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1282</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Return block of files, all dirs first</title>
      <link>http://snippets.dzone.com/posts/show/1271</link>
      <description>&lt;code&gt;&lt;br /&gt;    dir-file-sort: func [&lt;br /&gt;        {Returns the block of files with directories first, followed by&lt;br /&gt;        files, with each group sorted.}&lt;br /&gt;        block [any-block!]&lt;br /&gt;        /local result&lt;br /&gt;    ][&lt;br /&gt;        result: copy []&lt;br /&gt;        foreach blk lib/ser/split block [:dir?] none [&lt;br /&gt;            append result sort blk&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 01:58:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1271</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Get all sub-directories</title>
      <link>http://snippets.dzone.com/posts/show/1266</link>
      <description>&lt;code&gt;&lt;br /&gt;    dirs: func [&lt;br /&gt;        {Returns a block of fully qualified subdirectories for the directory.}&lt;br /&gt;        spec  [file!]   "Starting directory"&lt;br /&gt;        block [block!]  "Block to append to"&lt;br /&gt;        /deep           "Recurse sub-directories."&lt;br /&gt;        /local f-spec&lt;br /&gt;    ][&lt;br /&gt;        spec: dirize spec&lt;br /&gt;        foreach file read spec [&lt;br /&gt;            if dir? f-spec: join spec file [&lt;br /&gt;                append block f-spec&lt;br /&gt;                if deep [all-dirs/deep f-spec block]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;        block&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 01:55:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1266</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
