I need to create a C program (Normal C program compiled by Visual C
compiler) that read files from a particular directory to perform some
basic file handling under NT environment. They will be different files
come in each day to the directory. The problem is I don't know the exact
file name of those files. Kindly advise how can I open those file that
with different file name each day? Or any syntax that I can use to store
all of the file name of a particular directory into an array?
Hope can hearing from you soon. Thanks in advance.
You either know the name of the file or at least the structure of the file
name. For example you can say that the name of the file is XXX%02d%02d%02d
where the first %02d is the year, then the month and the day. In such a
situation you can sprintf the file name with the actual date into a buffer
and use the buffer to open the file.
If you do not knwo the name of the files at all and all you know that the
file is there then you have to get the names of the files that are in that
directory. To do that you can use the FileFind functions under Win32.
However I recommend that you program portable and thus later you will have
less problem if ever you have to port ypur program for UNIX.
To do so visit the site www.scriptbasic.com and download the source
package. This is quite big, almost 1M, but all you need is the file
filesys.c that contains ready and well tested routines running under
Windows NT as well as Linux, that do jobs like that.
[ back to toc ]