Author Topic: help getting files  (Read 545 times)

0 Members and 1 Guest are viewing this topic.

xteraco

  • Guest
help getting files
« on: July 22, 2006 »


first off i'm using gcc with codeblocks

ok, that said, here's my question

how do i read for files that are in the same dir as my program, all i want it to do is read, and save a list of filenames

Offline rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2323
  • Karma: 392
    • View Profile
    • http://www.rbraz.com/
Re: help getting files
« Reply #1 on: July 23, 2006 »
I hope this is what you looking for.

It works with Dev-cpp and Visual C 6.0, so it should work with Code::Blocks :)


Code: [Select]
/*
    FindFiles
    Dev_c++ example by Rbraz
*/

#include <windows.h>
#include <winbase.h>
#include <iostream>

using namespace std;

void FindFiles(char *path)
{
   WIN32_FIND_DATA fileinfo; // file information struct
   HANDLE search = FindFirstFile(path, &fileinfo);
   if(INVALID_HANDLE_VALUE == search) return;

   do
   {
        cout << "FileName = " << fileinfo.cFileName << endl; // Here you can do whatever you want with "fileinfo.cFileName" (display. save etc...)
   }
   while (FindNextFile(search, &fileinfo));

   FindClose(search);
}


int main(int argc, char *argv[])
{
    FindFiles("*"); // Search in the same path of your executable
    // FindFiles("c:\\*"); // Search in another path
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

rbz ^ Codigos
Challenge Trophies Won:

xteraco

  • Guest
Re: help getting files
« Reply #2 on: July 23, 2006 »
hey!! thats awesome! i havent had a chance tot test it out yet, but i will when i get on my main machine?

also, i was wondering where would be a good place to learn more stuff like that ((windows type stuff)

thnkx  for t hte help
-xteraco

Offline rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2323
  • Karma: 392
    • View Profile
    • http://www.rbraz.com/
Re: help getting files
« Reply #3 on: July 28, 2006 »
I don't know a specific place to learn it, but I have the Win32 API Reference that helps a lot, and when I have troubles with some command I try to serch help in the net. 
rbz ^ Codigos
Challenge Trophies Won: