<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; Помогите разобраться с кодом на С]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=8358&amp;type=atom" />
	<updated>2010-11-16T05:48:41Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=8358</id>
		<entry>
			<title type="html"><![CDATA[Re: Помогите разобраться с кодом на С]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=113472#p113472" />
			<content type="html"><![CDATA[<p>Спасибо буду разбираться... еще раз убедился что С\C++ очень не четабельный язык&nbsp; <img src="https://linuxforum.ru/img/smilies/ag.gif" alt="ag" /> <br />Тему прошу не закрывать. В плане еще маленькую GUI морду прилепить, но это после того, как разберусь с кодом.</p><p>UPD: Я чет стормозил, забыл что можно в man смотреть ))</p>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2010-11-16T05:48:41Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=113472#p113472</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите разобраться с кодом на С]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=113451#p113451" />
			<content type="html"><![CDATA[<p>примечание есть в man 3 readdir<br /></p><div class="quotebox"><blockquote><p>NOTES<br />&nbsp; &nbsp; &nbsp; &nbsp;Only&nbsp; the&nbsp; fields&nbsp; d_name&nbsp; and d_ino are specified in POSIX.1-2001.&nbsp; The remaining fields are available on<br />&nbsp; &nbsp; &nbsp; &nbsp;many, but not all systems.&nbsp; Under glibc, programs can check for the availability of the fields not defined<br />&nbsp; &nbsp; &nbsp; &nbsp;in POSIX.1 by testing whether the macros _DIRENT_HAVE_D_NAMLEN, _DIRENT_HAVE_D_RECLEN, _DIRENT_HAVE_D_OFF,<br />&nbsp; &nbsp; &nbsp; &nbsp;or _DIRENT_HAVE_D_TYPE are defined.</p></blockquote></div><p><s>т.ч. не везде это сработает...</s><br />хотя нет, везде, что-то я перепутал. как раз d_name будет работать везде.</p><p>в том-же мане сказано:<br /></p><div class="quotebox"><blockquote><p>On Linux, the dirent structure is defined as follows:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;struct dirent {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ino_t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d_ino;&nbsp; &nbsp; &nbsp; &nbsp;/* inode number */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;off_t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d_off;&nbsp; &nbsp; &nbsp; &nbsp;/* offset to the next dirent */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unsigned short d_reclen;&nbsp; &nbsp; /* length of this record */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unsigned char&nbsp; d_type;&nbsp; &nbsp; &nbsp; /* type of file; not supported<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; by all file system types */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d_name[256]; /* filename */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};</p></blockquote></div><p>из чего следует, что d_name просто имя файла. максимум 255 байтов (не букв! по русски это будет всего 127). В Windows несколько больше, потому файлы оттуда иногда не влезают в Linux.</p>]]></content>
			<author>
				<name><![CDATA[drBatty]]></name>
				<uri>https://linuxforum.ru/profile.php?id=86</uri>
			</author>
			<updated>2010-11-16T00:39:22Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=113451#p113451</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите разобраться с кодом на С]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=113195#p113195" />
			<content type="html"><![CDATA[<p>Вот как-то так...<br /></p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;errno.h&gt;
#include &lt;dirent.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;time.h&gt;

#define DIRNAME &quot;.&quot;

void showfiles(char *dir, int depth)
{
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;

    if ((dp = opendir(dir)) == NULL)
    {
        fprintf(stderr, &quot;Can not open directory: %s\n&quot;, dir);
        return;
    }
    chdir(dir);
    while ((entry = readdir(dp)) != NULL)
    {
        lstat(entry-&gt;d_name, &amp;statbuf);
        if (S_ISDIR(statbuf.st_mode))
        {
            if (strcmp(&quot;.&quot;, entry-&gt;d_name) == 0 ||
                    strcmp(&quot;..&quot;, entry-&gt;d_name) == 0)
                continue;
            showfiles(entry-&gt;d_name, depth + 4);
        }
        else
        {
            if (S_ISBLK(statbuf.st_mode)||S_ISCHR(statbuf.st_mode))
                continue;
            else
            {
                char *s_time = ctime(&amp;statbuf.st_mtime);
                fprintf(stdout,&quot;FileName = %s, Modification date = %s\n&quot;, entry-&gt;d_name, s_time);
            }
        }
    }
    chdir(&quot;..&quot;);
    closedir(dp);
}

int main(void)
{

    showfiles((char *)DIRNAME, 0);

    return 0;
}</code></pre></div><p>Тут осталось добавить аргументы в main: имя каталога, от которого начинается чтение (в двнный момент используется текущий - #define DIRNAME &quot;.&quot;) и дату модификации, передать их в функцию showfiles, где сравнивать с датой модификации текущего файла и печатать его название при совпадении. Если непонятно что-то, обращайтесь</p><p>З.Ы. Да, забыл еще, что вывод нужно, видимо, сделать с полным именем файла, типа<br /></p><div class="codebox"><pre><code>        
char *cwd = get_current_dir_name();
fprintf(stdout,&quot;FileName = %s/%s, Modification date = %s\n&quot;, cwd, entry-&gt;d_name, s_time);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Hvzh]]></name>
			</author>
			<updated>2010-11-15T11:20:41Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=113195#p113195</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите разобраться с кодом на С]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=112978#p112978" />
			<content type="html"><![CDATA[<p>читаем это <a href="http://citforum.ru/operating_systems/manpages/DIRENT.3.shtml">http://citforum.ru/operating_systems/ma … NT.3.shtml</a><br />. - это текущий каталог, .. - родительский каталог</p>]]></content>
			<author>
				<name><![CDATA[odin]]></name>
				<uri>https://linuxforum.ru/profile.php?id=7138</uri>
			</author>
			<updated>2010-11-14T19:02:35Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=112978#p112978</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Помогите разобраться с кодом на С]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=112946#p112946" />
			<content type="html"><![CDATA[<p>Есть код... отрыл в инете. Все вроде понятно, но не хватает знаний понят его полностью.<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;errno.h&gt;
#include &lt;dirent.h&gt;
 
#define DIRNAME &quot;.&quot;
#define OFNAME  &quot;out.log&quot;
 
int main(void)
{
    FILE *ofp;
    DIR *dp;
    struct dirent *dent;
 
    if( (dp = opendir(DIRNAME)) == NULL) {
        fprintf(stderr, &quot;opendir: %s: %s\n&quot;, DIRNAME, strerror(errno));
        return 1;
    }
    if( (ofp = fopen(OFNAME, &quot;w&quot;)) == NULL) {
        fprintf(stderr, &quot;fopen: %s: %s\n&quot;, OFNAME, strerror(errno));
        return 1;
    }
 
    while(dent = readdir(dp))
        if(strcmp(&quot;.&quot;, dent-&gt;d_name) &amp;&amp; strcmp(&quot;..&quot;, dent-&gt;d_name))
            fprintf(ofp, &quot;%s\n&quot;, dent-&gt;d_name);
    closedir(dp);
    fclose(ofp);
    return 0;
}</code></pre></div></div></div><p>Не понятно как тут работает цикл while. Вижу что сравнивает &quot;.&quot; с dent-&gt;d_name, но чет не вьеду в это. И что это за d_name. Подскажите. Я ламер и прошу не пинать ))</p><p>UPD: Мне нужно сделать программу, которая будет выдавать список всех файлов, которые были изменены за нужное мне число. Ну и где находятся они соответственно в громадном дереве директорий. Типо того.</p>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2010-11-14T17:08:07Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=112946#p112946</id>
		</entry>
</feed>
