finding a file(name)

T

tcwarrior

Hi all. I am trying to write a little program where I extract some
data out of a game in real time. The game writes some info to a log
file, and I can access this in real time. The problem is that the log
name is (partially) new every time so I can't just open any file.

Currently I have to first start the log, then copy the log name to my c
++ source file (fopen(logname)), then compile the source file and
after that run the extracting program, at which time the log has grown
a substantial amount.

What I want to do is just start the log and then start the extracting
program and it'll find the new logfile right away.

Good to know:
I can set the first part of the name manually. The game adds date and
time to it so the logfile name is e.g.:
mylogname_070208_180914.log

I can see two ways of solving this: Either search for the newest files
in the folder the log is created in, or open a file that starts with
"mylogname".

Anyone have a solution to this?

current code:
FILE *fileP; //fileP = file pointer
fileP = fopen("mylogname_070208_172648.log","r"); //bad code have to
copy paste every time
 
R

Rolf Magnus

Hi all. I am trying to write a little program where I extract some
data out of a game in real time. The game writes some info to a log
file, and I can access this in real time. The problem is that the log
name is (partially) new every time so I can't just open any file.

Currently I have to first start the log, then copy the log name to my c
++ source file (fopen(logname)), then compile the source file and
after that run the extracting program, at which time the log has grown
a substantial amount.

What I want to do is just start the log and then start the extracting
program and it'll find the new logfile right away.

Good to know:
I can set the first part of the name manually. The game adds date and
time to it so the logfile name is e.g.:
mylogname_070208_180914.log

I can see two ways of solving this: Either search for the newest files
in the folder the log is created in, or open a file that starts with
"mylogname".

Anyone have a solution to this?

There is no solution in standard C++. The closest you can get is by using
the boost filesystem library.
current code:
FILE *fileP; //fileP = file pointer
fileP = fopen("mylogname_070208_172648.log","r"); //bad code have to
copy paste every time

One improvement would be to take the name as a command line argument. That
way, at least you don't need to recompile your program each time the file
name changes.
 
M

Marcus Kwok

Hi all. I am trying to write a little program where I extract some
data out of a game in real time. The game writes some info to a log
file, and I can access this in real time. The problem is that the log
name is (partially) new every time so I can't just open any file.

Currently I have to first start the log, then copy the log name to my c
++ source file (fopen(logname)), then compile the source file and
after that run the extracting program, at which time the log has grown
a substantial amount.

What I want to do is just start the log and then start the extracting
program and it'll find the new logfile right away.

Good to know:
I can set the first part of the name manually. The game adds date and
time to it so the logfile name is e.g.:
mylogname_070208_180914.log

I can see two ways of solving this: Either search for the newest files
in the folder the log is created in, or open a file that starts with
"mylogname".

Anyone have a solution to this?

current code:
FILE *fileP; //fileP = file pointer
fileP = fopen("mylogname_070208_172648.log","r"); //bad code have to
copy paste every time

Maybe something in the Boost Filesystem library can help, but I haven't
had to use it yet:
http://www.boost.org/libs/filesystem/doc/index.htm
 
T

tcwarrior

I just had an idea... Although I don't know the exact filename I do
know the length of the filename. Anyway I can use this to make it
easier? (I'm thinking if I can list att files in a folder and make
sure this is the only file of specific length I can open it with a
simple if command.)

The boost filesystem library does not seem to have the desired command.
 
J

Jim Langston

Hi all. I am trying to write a little program where I extract some
data out of a game in real time. The game writes some info to a log
file, and I can access this in real time. The problem is that the log
name is (partially) new every time so I can't just open any file.

Currently I have to first start the log, then copy the log name to my c
++ source file (fopen(logname)), then compile the source file and
after that run the extracting program, at which time the log has grown
a substantial amount.

What I want to do is just start the log and then start the extracting
program and it'll find the new logfile right away.

Good to know:
I can set the first part of the name manually. The game adds date and
time to it so the logfile name is e.g.:
mylogname_070208_180914.log

I can see two ways of solving this: Either search for the newest files
in the folder the log is created in, or open a file that starts with
"mylogname".

Anyone have a solution to this?

current code:
FILE *fileP; //fileP = file pointer
fileP = fopen("mylogname_070208_172648.log","r"); //bad code have to
copy paste every time

You need something to get a list of files in the directory. Either use
Boost or something from your own OS. For windows look at findfirst() and
findnext() (_findfirst() and _findnext()). Not sure for *nix.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top