finding a file(name)

Discussion in 'C++' started by tcwarrior@hotmail.com, Feb 8, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Rolf Magnus Guest

    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.
     
    Rolf Magnus, Feb 8, 2007
    #2
    1. Advertising

  3. Marcus Kwok Guest

    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
     
    Marcus Kwok, Feb 8, 2007
    #3
  4. Guest

    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, 2007
    #4
  5. Jim Langston Guest

    <> wrote in message
    news:...
    > 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.
     
    Jim Langston, Feb 8, 2007
    #5
  6. Guest

    , Feb 9, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    876
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,876
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,426
    Joe Smith
    Apr 22, 2007
  4. Jack-2
    Replies:
    3
    Views:
    308
    Jack-2
    Dec 24, 2003
  5. Java  script  Dude

    IE name="name" & form.name property bug

    Java script Dude, Jun 29, 2004, in forum: Javascript
    Replies:
    5
    Views:
    269
    Java script Dude
    Jun 30, 2004
Loading...

Share This Page