473,657 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_07020 8_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("mylognam e_070208_172648 .log","r"); //bad code have to
copy paste every time

Feb 8 '07 #1
5 1775
tc*******@hotma il.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_07020 8_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("mylognam e_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*******@hotma il.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_07020 8_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("mylognam e_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*******@hotm ail.comwrote in message
news:11******** **************@ v45g2000cwv.goo glegroups.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_07020 8_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("mylognam e_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
18224
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 doc with script tag who's source is a javascript file. <HTML> <script src="javascript.js"></script> </HTML> Javascript.js
3
3001
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, _ Optional varTitleForDialog As Variant) As Variant ' Here's an example that gets an Access database name. Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant
3
1088
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 the entire application I want to print the name of all forms to the debug window. TIRislaa
6
1084
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
2325
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 either manually enter the path and file name, or to browse for the file. I do not want that. Ideally, I want the user to click on a link, and the server side php app does the rest. Again, the file always has the same name, and is in the same place....
5
3675
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 error so please help me how can i access font file name by font name in windows vista or what change i have to do in following function to get the solution my function source code is givin below -
4
7942
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 * name; cin >name;
185
7004
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 return the file name given a FILE *. Questions: What would be the best name for this function?
4
2943
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 picture successfully unto the server but not so with the file name of the picture even though other parameters in my form got inserted successfuly in the database. I have read several posts on this topic including here on this site but I can't get around...
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.