Entwickler-Ecke

Dateizugriff - Dateien kopieren, jedoch bereits vorhandene ignorieren


Chris2 - Mi 28.08.02 17:19
Titel: Dateien kopieren, jedoch bereits vorhandene ignorieren
Habe Zwei Rechner im Netzwerk, bei denen jeweils die c-platte freigegeben ist.

\\PC01\c
\\PC02\c

und möchte jetzt, dass die Dateien von \\PC01\c\windows\fonts
ins verzeichnis \\PC02\c\windows\fonts kopiert werden,
damit beide Rechner die gleichen Schriftarten besitzen.

beim Kopieren soll das Programm jedoch bereits vorhandene Dateien im Zielordner übergehen, um dann gleich mit der nächsten Datei fortzufahren.

wie lautet der kopierbefehl?


DeCodeGuru - Do 29.08.02 07:31

ich habe jetzt keine psdk oder delphihilfe vor mir, aber probier es mal mit CopyToFile (o.ä.) ich glaube, da kann man auch einstellen, dass schon existierende dateien überschrieben werden sollen.


Delete - Do 29.08.02 09:26

PSDK hat folgendes geschrieben:


Quelltext
1:
2:
3:
4:
5:
BOOL CopyFile(
  LPCTSTR lpExistingFileName, // name of an existing file
  LPCTSTR lpNewFileName,      // name of new file
  BOOL bFailIfExists          // operation if file exists
);


lpExistingFileName
[in] Pointer to a null-terminated string that specifies the name of an existing file.
Windows NT/2000/XP: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows 95/98/Me: This string must not exceed MAX_PATH characters.

lpNewFileName
[in] Pointer to a null-terminated string that specifies the name of the new file.
Windows NT/2000/XP: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows 95/98/Me: This string must not exceed MAX_PATH characters.

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.

Aber wenn ich mir das so ansehe, dann will Chris2 ja nicht, dass vorhandene Dateien überschrieben werden. Und diese Funktion tut das entweder, oder sie bricht ab!

Das einzige, was mir jetzt noch einfällt, wäre SHFileOperation, wobei man für die "SHFILEOPENSTRUCT"-Variable folgendes zusätzliche Flag benutzt:
PSDK hat folgendes geschrieben:
FOF_RENAMEONCOLLISION
Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.

Damit wird zumindest ein Abbruch verhindert. Nachteil: die schon vorhandene Datei wird mit einem neuen Namen trotzdem kopiert.

Ansonsten bleibt wohl nur der Weg über FindFirst/FindNext/FindClose, bei dem man jede Datei heraussucht, prüft, ob sie schon vorhanden ist, und ggf. kopiert.


Klabautermann - Do 29.08.02 09:55

Hallo,

du kannst bevor du CopyFile aufrufst die Existenz der Zieldatei mit FileExists überprüfen. Existiert sie Kopierst du sie eben nicht.

Gruß
Klabautermann