<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: directories code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 06:35:31 GMT</pubDate>
    <description>DZone Snippets: directories code</description>
    <item>
      <title>Listing the files and subdirectories in C - Linux</title>
      <link>http://snippets.dzone.com/posts/show/5734</link>
      <description>// program lists the files and subdirectories within a given directory in full path&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;#include &lt;dirent.h&gt;&lt;br /&gt;&lt;br /&gt;char *path_cat (const char *str1, char *str2);&lt;br /&gt;&lt;br /&gt;int main () {&lt;br /&gt;	struct dirent *dp;&lt;br /&gt;&lt;br /&gt;        // enter existing path to directory below&lt;br /&gt;	const char *dir_path="/path/to/directory/to/list";&lt;br /&gt;	DIR *dir = opendir(dir_path);&lt;br /&gt;	while ((dp=readdir(dir)) != NULL) {&lt;br /&gt;		char *tmp;&lt;br /&gt;		tmp = path_cat(dir_path, dp-&gt;d_name);&lt;br /&gt;		printf("%s\n", tmp);&lt;br /&gt;		free(tmp);&lt;br /&gt;		tmp=NULL;&lt;br /&gt;	}&lt;br /&gt;	closedir(dir);&lt;br /&gt;	return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;char *path_cat (const char *str1, char *str2) {&lt;br /&gt;	size_t str1_len = strlen(str1);&lt;br /&gt;	size_t str2_len = strlen(str2);&lt;br /&gt;	char *result;&lt;br /&gt;	result = malloc((str1_len+str2_len+1)*sizeof *result);&lt;br /&gt;	strcpy (result,str1);&lt;br /&gt;	int i,j;&lt;br /&gt;	for(i=str1_len, j=0; ((i&lt;(str1_len+str2_len)) &amp;&amp; (j&lt;str2_len));i++, j++) {&lt;br /&gt;		result[i]=str2[j];&lt;br /&gt;	}&lt;br /&gt;	result[str1_len+str2_len]='\0';&lt;br /&gt;	return result;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 08 Jul 2008 01:13:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5734</guid>
      <author>Tvrtko (Tvrtko)</author>
    </item>
    <item>
      <title>Delete empty directories (UNIX)</title>
      <link>http://snippets.dzone.com/posts/show/3012</link>
      <description>// Shell command to delete empty directories. May have to run several times to get everything.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find . -type d -empty | xargs rmdir -&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 18 Nov 2006 03:21:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3012</guid>
      <author>jasonbentley (Jason Bentley)</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>
