|
-
July 18th, 2006, 09:15 PM
#1
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;
}
}
-
July 18th, 2006, 09:29 PM
#2
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
-
July 18th, 2006, 11:52 PM
#3
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.
-
July 19th, 2006, 01:38 AM
#4
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
-
July 19th, 2006, 10:42 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|