Dateien Kopieren
-
Hallo,
Ich muss in einer einfachen Visual C++ 6.0 Konsolenanwendung alle Files vom Ordner Test, welcher im gleichen Verzeichnis liegt wie die exe, in den Ordner C:\Temp kopieren.
Da ich normalerweise .Net und C# Programmiere komme ich nicht weiter, kann mir jemand ein bisschen auf die Sprünge helfen bzgl. Dateien kopieren?Vielen Dank für die Hilfe
Grüsse
-
MSDN:
CopyFile
The CopyFile function copies an existing file to a new file.BOOL CopyFile(
LPCTSTR lpExistingFileName,
// pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
-
Mittels "GetModuleFileName(NULL, ...)" bekommst Du den Pfad auf die EXE (mittels spltpath). Dann kannst Du entweder CopyFile oder SHFileOperation verwenden...
-
Vielen Dank für die Tipps, hat bestens funktioniert, hier meine Lösung falls jemand mal ähnliches vorhat:
//Ermittelt den Applikationspfad CString GetApplicationDirectory() { TCHAR szPathName[255]; ::GetModuleFileName(NULL, szPathName, 255); LPTSTR pszFileName = _tcsrchr(szPathName, '\\') + 1; *pszFileName = '\0'; return szPathName; } //Kopiert alle Dateien void CopyFiles() { strSourcePath = GetApplicationDirectory() + "\\test"; strTragetPath = "C:\\Temp\\"; CFileFind finder; BOOL bWorking = finder.FindFile(strOEMPath + "\\*.*"); while (bWorking) { bWorking = finder.FindNextFile(); if (!finder.IsDirectory()) { CString strCopyPath; strCopyPath = strTragetPath + (LPCTSTR) finder.GetFileName(); CopyFile(finder.GetFilePath(), strCopyPath, 0); cout << (LPCTSTR) strCopyPath << " wurde erfolgreich kopiert." << endl; } } cout << "Der Kopiervorgang ist abgeschlossen." << endl; }
Grüsse