473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

finding a file(name)

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

Feb 8 '07 #1
5 1762
tc*******@hotmail.com wrote:
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.

Feb 8 '07 #2
tc*******@hotmail.com wrote:
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

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Feb 8 '07 #3
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.

Feb 8 '07 #4
<tc*******@hotmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
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.
Feb 8 '07 #5
I found a solution in the msdn library I could use this function

http://msdn2.microsoft.com/en-us/library/aa364428.aspx

and call it with main(mylogname*) and it found the file I wanted. The
* is the good thing here.

Feb 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
3
by: Wayne Aprato | last post by:
I am using code kindly provided by the Access Web to capture a file path and insert it into a form. The relevant part of the code follows: Function GetOpenFile(Optional varDirectory As Variant,...
3
by: Tor Inge Rislaa | last post by:
Finding name and type In the activate procedure of a form I want to write to the debug window, name and type of all controls at that actual form. Is there a smart way to do that? Allso for...
6
by: Tor Inge Rislaa | last post by:
Finding name of all forms I want to create a procedure that can loop trough all objects of type form in an application and print the name property to the debug window. TIRislaa
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
5
by: =?Utf-8?B?Qkw=?= | last post by:
Hello friends In c# 2005 I have written a function to access "font file name" by "Font name" and it is working fine in all the windows version other than vista, in vista it is throughing an...
4
by: carmelo | last post by:
Hi! I need to read and store data from a file, but I don't the name of it; Is this code correct and is there a better way to do this thing?? int main() { cout << " type file name:" char *...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.