CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Posts
    22

    Automatic Naming

    Hello guys, I'm creating a screenshot utility program which obviously takes screenshots. Anyways, I wanted to integrate a feature where one would specify a prefix, and then a number would be appended. For example, if my prefix were screen, and it was the third screen shot I took, it'd save the file as screen03, or something similar, I believe you get the point.

    Anyways, I already know how to save and what not, I was just wondering if you guys had an idea as to how I'd accomplish this. I was thinking about doing some type of FileExists method (Is there one already?), and then I'd check if the first shot existed, if it did, then iterate through until the last one didn't exist, then I'd save it as that. I don't know if you guys understand my approach here, if you don't it's okay, but if you do, I'd be greatful to hear your comments.

    Here's a rough, 'pseudo-code' visualization:

    Code:
    string file = "pic";
    int num = 1;
    
    while (true)
    {
       if (FileExists((file + num.ToString()) == true)
       {
          savefileas(file + num.ToString());
          break;
       }
    }

  2. #2
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Re: Automatic Naming

    that was how i did it to.

    another way i think is to retrieve the list of filenames inside the directory and search thru it.
    But i find the above method easier
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

  3. #3
    Join Date
    Jul 2005
    Posts
    22

    Re: Automatic Naming

    Yeah, there was actually an error in the code I posted, even if it was pseudo-code. I meant to savefileas(file + (num + 1).ToString());.

    Anyways, thanks, I'll just have to look for some type of FileExists method, thanks again ideru.

  4. #4
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Re: Automatic Naming

    actually to know if the file exist use the FileInfo class

    string filename ="your_filename";
    FileInfo fInfo = new FileInfo(filename);

    if( fInfo.Exist)
    {
    // do something
    }
    Exist is a property of FileInfo in boolean format
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

  5. #5
    Join Date
    Jul 2005
    Posts
    22

    Re: Automatic Naming

    Ah, but then I'd have to create one/define one each time I iterated through the filenames, someone told me to do System.IO.File.Exists(string path), but thanks for the help

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