CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    45

    Creating temp files with unique names.

    In my MFC MDI, when the user opens a file the program needs to create a temporary file. So because it is MDI I need to create a different temporary file name for each file opened, but I don't know how to do this. At the moment, my temp. file is called temp.txt, but this means that if the user opens a second input file my program crashes. How can I create different filenames for these temp files? I would like to use filenames of either of following formats: <inputfile>.tmp or temp1.txt, temp2.txt .
    Thank you,
    Sean.



  2. #2
    Join Date
    May 1999
    Posts
    40

    Re: Creating temp files with unique names.

    Check out the WIN32 function GetTempFileName or the ANSI C function tmpnam.

    You can also roll your own by building a string out of a a fixed prefix and a number that you keep incrementing. Before you create the next temp file search the directory you are writing the files to and if there is already a file with the name you want to use then increment the number. Much simpler to use one of the above functions.

    Josh



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured