Autor Beitrag
Maniacmd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mi 12.07.06 13:17 
ich bekomme eine datei nicht gelöscht. es tritt immer ein fehler auf.

ausblenden Delphi-Quelltext
1:
DeleteFile('C:\windows\'+(form1.ListBox1.Items.Strings[form1.ListBox1.Itemindex])  +'.txt');					



ich will eine datei mit dem name eines markierten items in der listbox löschen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 12.07.06 13:20 
user profile iconManiacmd hat folgendes geschrieben:
ich bekomme eine datei nicht gelöscht. es tritt immer ein fehler auf.
Sinnvoll in dem Zusammenhang wäre, wenn du mal sagst, was das für ein Fehler ist ;-)
Kompiliert es nicht, gibt es eine Zugriffsverletzung, wird die Datei einfach nur nicht gelöscht...?

_________________
We are, we were and will not be.
Softchaos67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Mi 12.07.06 13:24 
Zitat:

Sinnvoll in dem Zusammenhang wäre, wenn du mal sagst, was das für ein Fehler ist ;-)
Kompiliert es nicht, gibt es eine Zugriffsverletzung, wird die Datei einfach nur nicht gelöscht...?


Gibts das file überhaupt? Ist der Name korrekt?

_________________
cum grano salis
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 12.07.06 13:31 
Im Windows-Verzeichnis (und nicht nur da, aber da im Besonderen) kann es noch ganz andere Probleme geben:
- Datei ist in Benutzung
- Fehlende Rechte
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Mi 12.07.06 13:35 
desweiteren... wenn du das im Form1 irgendwo machst, kannst du vor der Listbox1 dein form1 weglassen

um zu testen, ob das wirklich ein korrekter dateiname ist, solltest du sowas drumherum bauen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  filename : string;
begin
  filename := 'C:\windows\'+(ListBox1.Items.Strings[ListBox1.Itemindex])+'.txt';
  if FileExists(filename) then begin
    if MessageDlg('Wollen Sie wirklich die Datei '+filename+' löschen?',
                  mtWarning, [mbYes, mbNo], 0) = mrYes then
      DeleteFile(filename);
  end else 
    ShowMessage('Die Datei '+filename+' wurde nicht gefunden!');
end;
Maniacmd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mi 12.07.06 13:41 
Die Datei existiert 100 prozentig

die Fehlermeldung ist:
listenindex überschreitet das maximum (-1)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 12.07.06 13:43 
Vielleicht prüfst du vorher auch mit FileExists(dateiname : string) : boolean ob es die Datei gibt.
Edit:// zu spät...

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Mi 12.07.06 13:44 
dann ist es keine fehlermeldung beim kopieren, sondern du hast noch keine datei (nichts in deiner listbox) ausgewählt
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mi 12.07.06 13:47 
...dann ist der ItemIndex -1, also solltest du vorher prüfen, ob der größer -1 ist.

_________________
Programmers never die, they just GOSUB without RETURN
Maniacmd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mi 12.07.06 13:49 
ne es war was anderes hab den fehler gefunden.
ich habe den listbox eintrag gelöscht bevor ich die dateiu gelöscht habe is eigentlich klar das dann nich gehen kann.
danke