Autor Beitrag
Hybrid
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112

Win XP Pro
D7 Ent
BeitragVerfasst: So 22.02.04 20:25 
Hi erstmal.
Ich hab da ein Problem mit einem Script zum speichern von Screenshots.
Das Script speichert die Screenshots als card#.bmp, wobei # für eine Zahl, die beim programmstart auf 0 gesetzt wird, steht und die bei jedem speichern um 1 erhöht wird.

Mein Problem ist, dass mein Prog, im Verzeichniss (welches mit der Variable "selected" angegeben wird) wo die Bilder gespeichert werden, nachschaun muss, ob ein Bild mit dem Namen card#.bmp vorhanden und welche zahl für # eingetragen ist.

Und bitte schlagt mir nicht vor, die Zahl in einer ini-Datei zu speichern, da ich die dann entweder in jedes, zum speichern ausgewählte Verzeichniss schreiben müsste, oder in einer ini-Datei alle Pfade mit Zahlen speichern müsste.

Achja, das müsste dann auch so funktionieren, dass wenn folgende Dateien vorhanden sind,
card1.bmp
card2.bmp
card3.bmp
card5.bmp
das Prog beim Speichern als card4.bmp speichert und beim nächsten Mal als card6.bmp.

mfg Andreas S.
alias Hybrid
Michael Stenzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 133


D3 Prof, D7 PE
BeitragVerfasst: So 22.02.04 23:33 
Hi Hybrid.

Folgende Funktion sollte Dir weiterhelfen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function GetNextFileName(Dir : string) : string;
var i : integer;
begin
     if (Length(Dir)>0) and (System.Copy(Dir,1,1) <>'\') then Dir := Dir + '\';
     i := 0;
     While FileExists(Format('%sCard%d.bmp',[Dir,i])) do;
     Result := Format('%sCard%d.bmp',[Dir,i]);
end;


mfg.
Michael.
Hybrid Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112

Win XP Pro
D7 Ent
BeitragVerfasst: Mo 23.02.04 11:22 
Leider klappt das noch nicht ganz. Das script lässt das programm immer hängen bleiben, weil es die datei creature0.bmp überschreiben will.
Hier ist mal daqs script:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
var
  Form1: TForm1;
  selected,selected2:string;
  zahl1,zahl2:integer;


[.........]


function GetNextFileNameC(Dir : string) : string;
begin
     if (Length(Dir)>0) and (System.Copy(Dir,1,1) <>'\') then Dir := Dir + '\';
     While FileExists(Format('%sCreature%d.bmp',[Dir,zahl1])) do;
     Result := Format('%sCreature%d.bmp',[Dir,zahl1]);
end;


[.........]


procedure TForm1.FormCreate(Sender: TObject);
begin
selected:=ExtractFilePath(ParamStr(0));
zahl1:=0;
end;


[.........]


procedure TForm1.Button3Click(Sender: TObject);
var
  Bmp: TBitmap;
begin
 timer1.Enabled:=false;
  Bmp := TBitmap.Create;
  try
    FormularScreenShot(Bmp, panel1.Handle);

    if selected='' then
     bmp.SaveToFile(GetNextFileNameC(ExtractFilePath(ParamStr(0))))
      else
       bmp.SaveToFile(GetNextFileNameC(selected));
    zahl1:=zahl1+1;

  finally
    Bmp.Free;
  end;

 timer1.Enabled:=true;
end;
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mo 23.02.04 11:38 
Das gibt ne endlosschleife, wenn die datei Creature0 existiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function GetNextFileName(Dir : string) : string;
var i : integer;
begin
 if Dir[length(dir)] <> '\' then
  Dir := Dir + '\';
 i := 0;
 while FileExists(Format('%sCreature%d.bmp',[Dir,i])) do
  inc(i);
 Result := Format('%sCreature%d.bmp',[Dir,i]);
end;
Hybrid Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112

Win XP Pro
D7 Ent
BeitragVerfasst: Mo 23.02.04 12:49 
Danke an euch, jetzt ist es perfekt und funzt :D