<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Write C program to detect and List files in window in Operating System - Microsoft</title>
    <link>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828034#M7359</link>
    <description>Henry,&lt;BR /&gt;&lt;BR /&gt;I found this for you from the net, it won't go into  the directory loop. But you can do little modification to do that too.&lt;BR /&gt;&lt;BR /&gt;Here is the code which will work exactly like "dir" command.&lt;BR /&gt;&lt;BR /&gt;#include &lt;WINDOWS.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;int EnumerateFiles(char start_dir[], BOOL use_start_dir)&lt;BR /&gt;{&lt;BR /&gt; WIN32_FIND_DATA find_data;&lt;BR /&gt; HANDLE find_h;&lt;BR /&gt; DWORD find_ret;&lt;BR /&gt; SYSTEMTIME creation_time, access_time;&lt;BR /&gt; int ret;&lt;BR /&gt; char *file_name, atts, dir[MAX_PATH];&lt;BR /&gt; &lt;BR /&gt; if(use_start_dir)&lt;BR /&gt; {&lt;BR /&gt;  strcpy(dir, start_dir);&lt;BR /&gt;  //if(strrchr(start_dir, '.') == NULL) strcat(dir, "*.*");&lt;BR /&gt; }&lt;BR /&gt; else strcpy(dir, "*");&lt;BR /&gt; &lt;BR /&gt; ret = 0;&lt;BR /&gt; find_h = FindFirstFile(dir, &amp;amp;find_data);&lt;BR /&gt; if(find_h != INVALID_HANDLE_VALUE)&lt;BR /&gt; {&lt;BR /&gt;  puts("(&lt;D&gt; - Directory, &lt;S&gt; - System File, &lt;R&gt; - Read Only, &lt;H&gt; - Hidden)");&lt;BR /&gt;  puts("Created\t\tLast Accessed\tAttributes\tName\n");&lt;BR /&gt;  &lt;BR /&gt;  do&lt;BR /&gt;  {&lt;BR /&gt;   /*Keep track of how many attributes for alignment purposes*/&lt;BR /&gt;   atts = 0;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_DIRECTORY) atts++;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_SYSTEM) atts++;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_READONLY) atts++;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_HIDDEN) atts++;&lt;BR /&gt;   &lt;BR /&gt;   FileTimeToSystemTime(&amp;amp;find_data.ftCreationTime, &amp;amp;creation_time);&lt;BR /&gt;   FileTimeToSystemTime(&amp;amp;find_data.ftLastAccessTime, &amp;amp;access_time);&lt;BR /&gt;   if((file_name = strrchr(find_data.cFileName, '\\')) != NULL) file_name++;&lt;BR /&gt;   else file_name = find_data.cFileName;&lt;BR /&gt;   &lt;BR /&gt;   printf("%s%d/%s%d/%d\t%s%d/%s%d/%d\t%s%s%s%s%s\t%s\n", /*so messy!*/&lt;BR /&gt;    ((creation_time.wDay &amp;lt; 10) ? "0" : ""), creation_time.wDay, &lt;BR /&gt;    ((creation_time.wMonth &amp;lt; 10) ? "0" : ""), creation_time.wMonth, &lt;BR /&gt;    creation_time.wYear, ((access_time.wDay &amp;lt; 10) ? "0" : ""), access_time.wDay, &lt;BR /&gt;    ((access_time.wMonth &amp;lt; 10) ? "0" : ""), access_time.wMonth, creation_time.wYear, &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_DIRECTORY) ? "&lt;D&gt;" : ""), &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_SYSTEM) ? "&lt;S&gt;" : ""), &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_READONLY) ? "&lt;R&gt;" : ""), &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_HIDDEN) ? "&lt;H&gt;" : ""), &lt;BR /&gt;    ((atts &amp;gt; 2) ? "" : "\t"), /*alignment purposes...*/&lt;BR /&gt;    file_name);&lt;BR /&gt;   &lt;BR /&gt;   if(ret) break;&lt;BR /&gt;   if(!FindNextFile(find_h, &amp;amp;find_data)) find_ret = GetLastError();&lt;BR /&gt;   else find_ret = 0;&lt;BR /&gt;  }&lt;BR /&gt;  while(find_ret != ERROR_NO_MORE_FILES);&lt;BR /&gt;  FindClose(find_h);&lt;BR /&gt; }&lt;BR /&gt; else ret = 1;&lt;BR /&gt; &lt;BR /&gt; return ret;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; int ret;&lt;BR /&gt; char *error = 0;&lt;BR /&gt; &lt;BR /&gt; if(argc == 1) ret = EnumerateFiles(0, FALSE);&lt;BR /&gt; else if(argc == 2) ret = EnumerateFiles(argv[1], TRUE);&lt;BR /&gt; else EnumerateFiles(0, FALSE);&lt;BR /&gt; &lt;BR /&gt; switch(ret)&lt;BR /&gt; {&lt;BR /&gt;  case 0 : break;&lt;BR /&gt;  case 1 : error = "Invalid directory or no specified files within such a directory"; break;&lt;BR /&gt;  default : error = "Unknown error"; break;&lt;BR /&gt; }&lt;BR /&gt; if(error) puts(error);&lt;BR /&gt; &lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;/H&gt;&lt;/R&gt;&lt;/S&gt;&lt;/D&gt;&lt;/H&gt;&lt;/R&gt;&lt;/S&gt;&lt;/D&gt;&lt;/STDIO.H&gt;&lt;/WINDOWS.H&gt;</description>
    <pubDate>Fri, 21 Jul 2006 17:00:47 GMT</pubDate>
    <dc:creator>Arch_Muthiah</dc:creator>
    <dc:date>2006-07-21T17:00:47Z</dc:date>
    <item>
      <title>Write C program to detect and List files in window</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828032#M7357</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt; Is there anyway to write a C program to detect the represent of a file and to list files in a directory in windows?&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
      <pubDate>Fri, 21 Jul 2006 05:04:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828032#M7357</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-07-21T05:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Write C program to detect and List files in window</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828033#M7358</link>
      <description>Henry,&lt;BR /&gt;&lt;BR /&gt;If you want to use BAT program, it is easy.&lt;BR /&gt;The following two lines BAT code will create a .txt file with list of files from any drive or folder you pass. This output file can be fopened from your C program and can be listed.&lt;BR /&gt;=======&lt;BR /&gt;@echo off&lt;BR /&gt;dir "D:\" &amp;gt; C:\list_of_program_files.txt&lt;BR /&gt;========&lt;BR /&gt;&lt;BR /&gt;Archunan&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Jul 2006 16:59:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828033#M7358</guid>
      <dc:creator>Arch_Muthiah</dc:creator>
      <dc:date>2006-07-21T16:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Write C program to detect and List files in window</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828034#M7359</link>
      <description>Henry,&lt;BR /&gt;&lt;BR /&gt;I found this for you from the net, it won't go into  the directory loop. But you can do little modification to do that too.&lt;BR /&gt;&lt;BR /&gt;Here is the code which will work exactly like "dir" command.&lt;BR /&gt;&lt;BR /&gt;#include &lt;WINDOWS.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;int EnumerateFiles(char start_dir[], BOOL use_start_dir)&lt;BR /&gt;{&lt;BR /&gt; WIN32_FIND_DATA find_data;&lt;BR /&gt; HANDLE find_h;&lt;BR /&gt; DWORD find_ret;&lt;BR /&gt; SYSTEMTIME creation_time, access_time;&lt;BR /&gt; int ret;&lt;BR /&gt; char *file_name, atts, dir[MAX_PATH];&lt;BR /&gt; &lt;BR /&gt; if(use_start_dir)&lt;BR /&gt; {&lt;BR /&gt;  strcpy(dir, start_dir);&lt;BR /&gt;  //if(strrchr(start_dir, '.') == NULL) strcat(dir, "*.*");&lt;BR /&gt; }&lt;BR /&gt; else strcpy(dir, "*");&lt;BR /&gt; &lt;BR /&gt; ret = 0;&lt;BR /&gt; find_h = FindFirstFile(dir, &amp;amp;find_data);&lt;BR /&gt; if(find_h != INVALID_HANDLE_VALUE)&lt;BR /&gt; {&lt;BR /&gt;  puts("(&lt;D&gt; - Directory, &lt;S&gt; - System File, &lt;R&gt; - Read Only, &lt;H&gt; - Hidden)");&lt;BR /&gt;  puts("Created\t\tLast Accessed\tAttributes\tName\n");&lt;BR /&gt;  &lt;BR /&gt;  do&lt;BR /&gt;  {&lt;BR /&gt;   /*Keep track of how many attributes for alignment purposes*/&lt;BR /&gt;   atts = 0;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_DIRECTORY) atts++;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_SYSTEM) atts++;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_READONLY) atts++;&lt;BR /&gt;   if(find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_HIDDEN) atts++;&lt;BR /&gt;   &lt;BR /&gt;   FileTimeToSystemTime(&amp;amp;find_data.ftCreationTime, &amp;amp;creation_time);&lt;BR /&gt;   FileTimeToSystemTime(&amp;amp;find_data.ftLastAccessTime, &amp;amp;access_time);&lt;BR /&gt;   if((file_name = strrchr(find_data.cFileName, '\\')) != NULL) file_name++;&lt;BR /&gt;   else file_name = find_data.cFileName;&lt;BR /&gt;   &lt;BR /&gt;   printf("%s%d/%s%d/%d\t%s%d/%s%d/%d\t%s%s%s%s%s\t%s\n", /*so messy!*/&lt;BR /&gt;    ((creation_time.wDay &amp;lt; 10) ? "0" : ""), creation_time.wDay, &lt;BR /&gt;    ((creation_time.wMonth &amp;lt; 10) ? "0" : ""), creation_time.wMonth, &lt;BR /&gt;    creation_time.wYear, ((access_time.wDay &amp;lt; 10) ? "0" : ""), access_time.wDay, &lt;BR /&gt;    ((access_time.wMonth &amp;lt; 10) ? "0" : ""), access_time.wMonth, creation_time.wYear, &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_DIRECTORY) ? "&lt;D&gt;" : ""), &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_SYSTEM) ? "&lt;S&gt;" : ""), &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_READONLY) ? "&lt;R&gt;" : ""), &lt;BR /&gt;    ((find_data.dwFileAttributes &amp;amp; FILE_ATTRIBUTE_HIDDEN) ? "&lt;H&gt;" : ""), &lt;BR /&gt;    ((atts &amp;gt; 2) ? "" : "\t"), /*alignment purposes...*/&lt;BR /&gt;    file_name);&lt;BR /&gt;   &lt;BR /&gt;   if(ret) break;&lt;BR /&gt;   if(!FindNextFile(find_h, &amp;amp;find_data)) find_ret = GetLastError();&lt;BR /&gt;   else find_ret = 0;&lt;BR /&gt;  }&lt;BR /&gt;  while(find_ret != ERROR_NO_MORE_FILES);&lt;BR /&gt;  FindClose(find_h);&lt;BR /&gt; }&lt;BR /&gt; else ret = 1;&lt;BR /&gt; &lt;BR /&gt; return ret;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; int ret;&lt;BR /&gt; char *error = 0;&lt;BR /&gt; &lt;BR /&gt; if(argc == 1) ret = EnumerateFiles(0, FALSE);&lt;BR /&gt; else if(argc == 2) ret = EnumerateFiles(argv[1], TRUE);&lt;BR /&gt; else EnumerateFiles(0, FALSE);&lt;BR /&gt; &lt;BR /&gt; switch(ret)&lt;BR /&gt; {&lt;BR /&gt;  case 0 : break;&lt;BR /&gt;  case 1 : error = "Invalid directory or no specified files within such a directory"; break;&lt;BR /&gt;  default : error = "Unknown error"; break;&lt;BR /&gt; }&lt;BR /&gt; if(error) puts(error);&lt;BR /&gt; &lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;/H&gt;&lt;/R&gt;&lt;/S&gt;&lt;/D&gt;&lt;/H&gt;&lt;/R&gt;&lt;/S&gt;&lt;/D&gt;&lt;/STDIO.H&gt;&lt;/WINDOWS.H&gt;</description>
      <pubDate>Fri, 21 Jul 2006 17:00:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828034#M7359</guid>
      <dc:creator>Arch_Muthiah</dc:creator>
      <dc:date>2006-07-21T17:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Write C program to detect and List files in window</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828035#M7360</link>
      <description>Hi Archunan,&lt;BR /&gt;&lt;BR /&gt;  Thanks for the info, actually what i was intending to achieve is to able to copy files with the same name over the a directory without having to delete the old files. For example, the new files will be renamed to file01, file02 and so forth. Is there a easy way to to this?&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
      <pubDate>Sat, 22 Jul 2006 03:50:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/write-c-program-to-detect-and-list-files-in-window/m-p/3828035#M7360</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-07-22T03:50:44Z</dc:date>
    </item>
  </channel>
</rss>

