Some sample code

Just two questions today.

Could someone point me in the right direction to search for and delete certain files in a certain folder, say, desktop? (Using C++ , of course)

And also, how do you make a visual studio or Code Blocks C++ program run on computer startup?

I'm using a 64 bit Windows 7 computer, I have access to Visual studio AND Code::Blocks whichever turns out easier.
Okay, that helps a lot... How do I search through a directory? For example, is there a way to make a list of all the children of a file/directory like table[] = file.GetFiles()?
One way to display all the files in a directory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <windows.h>
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
  WIN32_FIND_DATA FindFileData;
  HANDLE hFind;
  char szFolder[] = "C:\\Temp\\*.*";

  cout << "Files in " << szFolder << endl;

  hFind = FindFirstFile(szFolder, &FindFileData);
  if (hFind == INVALID_HANDLE_VALUE) 
  {
    cout << "Error " << endl;
    exit(-1);
  }
  while ( FindNextFile(hFind, &FindFileData))
    if (FindFileData.cFileName[0] != '.')
      cout << FindFileData.cFileName << endl;

  FindClose(hFind);
  
  system("pause");
}
Topic archived. No new replies allowed.