Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autosave Image and autoname 1

Status
Not open for further replies.

Ante0

Programmer
Apr 19, 2007
98
SE
Hi, I made this screenshot program that takes a screenshot of desktop.
And I use shortcut Ctrl+s to save it to a file with (ExtractFilePath(ParamStr(0))+'Image.bmp');
Now, If I want to autoname the Image.bmp with numbers 01-99 like this: Image[number].bmp
How should I go forward with this?
I'm aware that I'd need to use If FileExists, but that's about as far as I've gotten.
Thanks again :)
 
more something like this :

(untested)
Code:
function UniqueFilename(Path : string) : string;

const FNTemplate = '%sImage%.2d.bmp';
var Index : Integer;   

begin
 Index := -1;
 repeat
  Inc(Index);
  Result := Format(FNTemplate, [Path, Index]) ;
 until not FileExists(Result);
end;

function is called like this :

MyFile := UniqueFilename(ExtractFilePath(ParamStr(0));

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Wow, Thanks daddy, works like a charm :D
Didn't even need to edit anything.
Thanks again!
//Ante0
 
Awsome bit of code, 1 for the library.
good to note that daddys code wont always put
your image to the end.

if you have

image1
image2
image4
image5
image6

then the next image saved will be image3

Aaron
 
in fact the function will format names like this:

image01
image02
...

if you need more space (let's say 4 digits), change the '%.2d' part into '%.4d'

you'll get something like this:

image0000
image0001
image0002
...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top