Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Copy File Problem - Überschreiben (https://www.delphipraxis.net/151471-copy-file-problem-ueberschreiben.html)

Dönerboy 19. Mai 2010 13:40


Copy File Problem - Überschreiben
 
Hallo alle zusammen, ich Hab ein Problem mit CopyFile, undzwar funktioniert das kopieren einwandfrei, aber sobald die Datei schon im Ordner ist (im Beispiel ein Textdokument) und ich dieses mit einer neueren Version Überschreiben will, passiert nicht, also die Datei kommt erst neu, wenn ich die alte gelöscht/umbenannt habe.

Was kann ich tun, damit die Datei reinkopiert wird?

Hier mal der Code:
Delphi-Quellcode:
procedure TOKRightDlg.Checking;
begin
if CheckListBox1.Checked[0]=TRUE then
begin
Copyfile(PWideChar((extractfilepath(application.ExeName) + 'files\data\Test.txt'), PWideChar(extractfilepath(open1.FileName) + 'Test.txt'), True);
end;
Habe es auch schon mit False am ende getestet, keine änderung

Luckie 19. Mai 2010 13:44

Re: Copy File Problem - Überschreiben
 
*seufz*

Macht doch endlich mal eine vollständige Fehlerbehandlung, dann wisst ihr auch, warum es nicht funktioniert hat:
Delphi-Quellcode:
if not CopyFile(...) then
  ShowMessage(SysErrorMessage(GetLastError));

Dönerboy 19. Mai 2010 13:46

Re: Copy File Problem - Überschreiben
 
Zitat:

Zitat von Luckie
*seufz*

Macht doch endlich mal eine vollständige Fehlerbehandlung, dann wisst ihr auch, warum es nicht funktioniert hat:
Delphi-Quellcode:
if not CopyFile(...) then
  ShowMessage(SysErrorMessage(GetLastError));

Toll, dann sagt er " Die Datei ist schon vorhanden", darum handelt es sich ja hier

Luckie 19. Mai 2010 13:48

Re: Copy File Problem - Überschreiben
 
Hilfe zum letzten Parameter:
Zitat:

bFailIfExists [in]
If this parameter is TRUE and the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

Soll die Datei überschriben werden, muss dort False stehen.

shmia 19. Mai 2010 13:50

Re: Copy File Problem - Überschreiben
 
Zitat:

Zitat von Dönerboy
Toll, dann sagt er " Die Datei ist schon vorhanden"

Das ist doch schon mal eine sehr wertvolle Information.
Hast du dich noch nicht gefragt, wozu eigentlich der 3. Parameter bei CopyFile() zuständig ist?
An dieser Stelle kann ich schon das "Klatsch" hören, wenn dein Hand auf die Stirn trifft...

Dönerboy 19. Mai 2010 13:50

Re: Copy File Problem - Überschreiben
 
Zitat:

Zitat von Luckie
Hilfe zum letzten Parameter:
Zitat:

bFailIfExists [in]
If this parameter is TRUE and the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

Soll die Datei überschriben werden, muss dort False stehen.

Danke, komischerweise geht es jetzt, eben war bei false auchnoch der error, naja egal

Ich danke dir;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz