Build a list of all CSV files

Posted By: YoungPete

Build a list of all CSV files - 02/04/15 00:55

I'm wanting to build a list of all CSV files. The list will do a recursive find on a particular path. Will this do the job, are are there more recent libraries to glean from ?

Code:
#include <acknex.h>
#include <windows.h>
#include <stdio.h>

typedef struct _FILETIME {
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
} 
_FILETIME; 

typedef struct _WIN32_FIND_DATA {
  DWORD dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD nFileSizeHigh;
  DWORD nFileSizeLow;
  DWORD dwReserved0;
  DWORD dwReserved1;
  char cFileName[ MAX_PATH ];
  char cAlternateFileName[ 14 ];
} 
_WIN32_FIND_DATA;

char main_str[10000];

int list_files(char *dir)
{
   HANDLE main_handle;
   WIN32_FIND_DATA main_data;
   char path_str[500];

   main_handle = FindFirstFile(dir,&main_data);
   
   while(FindNextFile(main_handle,&main_data))
   {
      switch(main_data.dwFileAttributes)
      {
         case FILE_ATTRIBUTE_DIRECTORY:
            sprintf(main_str,"[dir]");
            sprintf(main_str,main_data.cFileName);
            sprintf(main_str,"\n");
            GetFullPathName(main_data.cFileName,path_str,4096,NULL);
            list_files(path_str);
            break;
         default:
            sprintf(main_str,"[file]");
            sprintf(main_str,main_data.cFileName);
            sprintf(main_str,"\n");
      }
	}      
}

int main()
{
   wait(1);
   list_files("Data\\*.csv");
}



I only have Zorro at present, but wanted to use Lite-C. Found a link to download Lite-C (http://server.conitec.net/down/gstudio_setup.exe) but it didn't work. Downloaded Gamestudio 8 as a free version. Tried the code above, compiled okay, but then got an error - "Error E1241 Can't open DirectX device".

Thanks,

Pete
Posted By: sivan

Re: Build a list of all CSV files - 02/04/15 08:22

in gamestudio we use txt_for_dir for this purpose, that creates STRINGs containing all file names according to the given STRING filter, within the given TEXT.
Posted By: YoungPete

Re: Build a list of all CSV files - 02/04/15 23:52

Thanks, have found the documentation for it at http://www.conitec.net/beta/txt_for_dir.htm
© 2024 lite-C Forums