Autor Beitrag
BlackPhantom
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 144

Win 2000, Win XP, UNIX
D7 Prof, C, HTML, VB 5
BeitragVerfasst: So 29.06.03 19:55 
Hi@all

In meinem kleinen Prog kann ein Benutzer kleine Texte verfassen und in einer TXT abspeichern. Was ich jedoch gerne möchte ist folgendes:
Wenn der Benutzer abspeichert, soll das Prog automatisch die erste Zeile des geschriebenen Textes (meist ist das der Titel) als Dateinamen der TXT-file verwenden.

Ein Problem nebenbei:
Wenn ich zwei Dateien mit dem gleichen Dateinamen habe, wird eins überschrieben.. Ich möchte jedoch, dass bei einer zweiten Datei gleichen Names beim zweiten File in Klammer eine 2 auftaucht und so weiter.

Datensatz.txt
Datensatz(2).txt

thx4all
BlackP
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: So 29.06.03 20:04 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if FileExists(NormalerFilename) then begin
x := 2;
while FileExists (copy (NormalerFilename, 1, length (NormalerFilename) 
  - (Length (ExtractFileExt (NormalerFilename)) +1
  + '(' + IntToStr (x) + ').' + ExtractFileExt (NormalerFilename))
do 
  inc(x);

Nach der Schleife kannst du mit
ausblenden Delphi-Quelltext
1:
2:
3:
copy (NormalerFilename, 1, length (NormalerFilename) 
  - (Length (ExtractFileExt (NormalerFilename)) +1 ) 
  + '(' + IntToStr (x) + ').' + ExtractFileExt (NormalerFilename)

Den Entsprechenden Filename herausbekommen...

Moderiert von user profile iconTino: Absätze im Code eingefügt.

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: So 29.06.03 20:28 
anstatt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
while FileExists (copy (NormalerFilename, 1, length (NormalerFilename) 
  - (Length (ExtractFileExt (NormalerFilename)) +1
  + '(' + IntToStr (x) + ').' + ExtractFileExt (NormalerFilename)) 
do
  inc(x);

kannst du auch folgendes nehmen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
while FileExists(ChangeFileExt(NormalerFilename, '') + '(' 
  + IntToStr(x) + ').' + ExtractFileExt(NormalerFilename)) 
Do 
  inc(x);

ist etwas kürzer und übersichtlicher

Moderiert von user profile iconTino: Absätze im Code eingefügt.


Zuletzt bearbeitet von Phantom1 am Di 01.07.03 07:50, insgesamt 1-mal bearbeitet
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: So 29.06.03 20:31 
Mir ist grade ehrlich gesagt auf die schnelle nix kürzeres eingefallen... ;)

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
BlackPhantom Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 144

Win 2000, Win XP, UNIX
D7 Prof, C, HTML, VB 5
BeitragVerfasst: Mo 30.06.03 22:47 
Unglaublich !!! Danke .....ich habe ehrlich gesagt viel komplizierter gedacht, als ihr es hier vorgeschlagen habt. Nochmals danke euch beiden.