Search Directory for file type and copy

C++ Noob

I am trying to write a small console program to make my life easier at work. I need to back up several files, but the files are usually associated with the end user in some way or another. So the file names are never the same, so I need to conduct a search by extension.

.NSF - 6 files

.ID - 1 file

The only files that use those extensions are the files I need.

So far my program creates a new folder, and then grabs a few files that are always the same and copies them into the folder. I am stuck at finding the random named file and copying them into the new folder. I have read about using boost library, but I want to do this without using it as my work blocks the download.

If you have an example I would really appreciate it, as long as its easy enough for a noob to halfway understand.

bump.
$ program.bin /path/to/the/files/*.{NSF,ID}
Thanks ne555 I will try that out once I get some free time.
The way I did something like this was to make a bat file that would create a file list. I'm still looking for a way to search files and sub folders in C++ myself.

1
2
3
4
backup.bat
cd \<folder to search>
dir /b/s *.nsf > backup.txt
dir /b/s *.id >> backup.txt


Then call the C++ program to create directory, move the files, update log file or what ever else you need.

----

This program is not mine, but the closest I have found to create a file list. It only works on a single folder and it displays files and folders. I haven't had a chance to see if I could limit the output to a specific file name or search subfolders.

Hopefully gives you some ideas.

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
29
30
31
32
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<dirent.h>
#include<string.h>

int main()
{
        char dirn[50];
        DIR *dir = NULL;
        struct dirent *drnt = NULL;

        printf("Input dir name: ");
        gets(dirn);

        dir=opendir(dirn);
        if(dir)
        {
                printf("output:\n");
                while(drnt = readdir(dir))
                {
                        printf("%-20s\n", drnt->d_name);
                }
                closedir(dir);
        }
        else
        {
                printf("Can not open directory '%s'\n", dirn);
        }

        return 0;
}
ne555 can you go into more detail on:

$ program.bin /path/to/the/files/*.{NSF,ID}
Pass the files as arguments to your program.
closed account (Dy7SLyTq)
#include <dirent.h>
Topic archived. No new replies allowed.