N
Nathan Young
Hello.
Perhaps this isn't really a .NET question, but I'm hoping there is an
easy solution within .NET/VC++.
The problem: I have a directory full of different types of data files
and I need to grab the latest copy of data to load into my program.
Example:
ABC123.txt 01-01-2004 1:01a
ABC124.txt 01-02-2004 1:02a
ABC125.txt 01-03-2004 1:03a
ABC126.txt 01-04-2004 1:04a
ABC127.txt 01-04-2004 1:02a
XYZ123.txt 01-01-2004 1:01a
XYZ124.txt 01-02-2004 1:02a
XYZ125.txt 01-03-2004 1:04a
.... and so on.
I want to be able to search this directory, detect the latest ABC*.txt
file, and then open it. The filename is not coded with the date
information - that is the ABC123.txt filename has no significance vs
ABC124.txt. So, I have to retrieve it from the date/time stamp on the
file. In this case, the goal would be to identify the ABC126.txt file
generated on 01-04-2004 at 1:04a as it is the latest copy of the ABC*
files.
In order to accomplish this - I use a MS-DOS 'dir' command called by
system (as follows):
sprintf((char *)&shellCommand,"dir c:\\files\\ABC*.txt /b /o-d >
filelisting.txt");
system(shellCommand);
in = fopen("metarfiles.txt","r");
fscanf(in,"%s",&filename);
fclose(in);
I then open 'filename' and can access the data I want. This works
fine, but is a giant kludge. Nothing like seeing the DOS command
shell pop on top of my program for a brief second to remind me my
programming skills are not that good...
Anyway, there has to be an easier way to do this without leaving
..NET/VC++, right?
If it helps, the directory name is hardcoded, I do not have to
traverse the C:\ directories to find my subdirectory.
Thanks,
-Nathan
Perhaps this isn't really a .NET question, but I'm hoping there is an
easy solution within .NET/VC++.
The problem: I have a directory full of different types of data files
and I need to grab the latest copy of data to load into my program.
Example:
ABC123.txt 01-01-2004 1:01a
ABC124.txt 01-02-2004 1:02a
ABC125.txt 01-03-2004 1:03a
ABC126.txt 01-04-2004 1:04a
ABC127.txt 01-04-2004 1:02a
XYZ123.txt 01-01-2004 1:01a
XYZ124.txt 01-02-2004 1:02a
XYZ125.txt 01-03-2004 1:04a
.... and so on.
I want to be able to search this directory, detect the latest ABC*.txt
file, and then open it. The filename is not coded with the date
information - that is the ABC123.txt filename has no significance vs
ABC124.txt. So, I have to retrieve it from the date/time stamp on the
file. In this case, the goal would be to identify the ABC126.txt file
generated on 01-04-2004 at 1:04a as it is the latest copy of the ABC*
files.
In order to accomplish this - I use a MS-DOS 'dir' command called by
system (as follows):
sprintf((char *)&shellCommand,"dir c:\\files\\ABC*.txt /b /o-d >
filelisting.txt");
system(shellCommand);
in = fopen("metarfiles.txt","r");
fscanf(in,"%s",&filename);
fclose(in);
I then open 'filename' and can access the data I want. This works
fine, but is a giant kludge. Nothing like seeing the DOS command
shell pop on top of my program for a brief second to remind me my
programming skills are not that good...
Anyway, there has to be an easier way to do this without leaving
..NET/VC++, right?
If it helps, the directory name is hardcoded, I do not have to
traverse the C:\ directories to find my subdirectory.
Thanks,
-Nathan