#include <windows.h> #include <stdio.h> int main() { printf("%s\n", CopyFile("C:\\cop\\cop\\output.txt", "C:\\cop\\cop\\input.txt", FALSE) ? "Ok" : "Echec"); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionCopyFile("input.txt", "output.txt", FALSE) ;
system("copy input.txt output.txt");
Méthode avec CopyFile, évidemment.
remove("test.txt");
Essaie DeleteFile avec comme paramètre "fichier*.txt"
#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { DeleteFile("C:\\cop\\cop\\fichier*.txt",FALSE); }
1>c:\cop\cop\copie.c(10) : warning C4020: 'DeleteFileA' : paramètres réels trop nombreux
#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { DeleteFile("C:\\cop\\cop\\fichier*.txt"); return 0; }
#include <Windows.h> int main(int argc, char* argv[]) { char szPath[256]; char szSearch[256]; strcpy(szPath,"C:\\cop\\cop\"); strcpy(szSearch,szPath); strcat(szSearch,"*.txt"); WIN32_FIND_DATA wfd; HANDLE hfl = FindFirstFile(szSearch, &wfd); if(hfl == INVALID_HANDLE_VALUE) return 0; do { char szFile[256]; strcpy(szFile,szPath); strcat(szFile,wfd.cFileName); DeleteFile(szFile); } while(FindNextFile(hfl, &wfd)); FindClose(hfl); return 0; }
1>------ Début de la génération : Projet : cop, Configuration : Debug Win32 ------
1>Compilation en cours...
1>copie.c
1>c:\cop\cop\copie.c(59) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : voir la déclaration de 'strcpy'
1>c:\cop\cop\copie.c(61) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : voir la déclaration de 'strcpy'
1>c:\cop\cop\copie.c(63) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\string.h(79) : voir la déclaration de 'strcat'
1>c:\cop\cop\copie.c(65) : error C2275: 'WIN32_FIND_DATA' : utilisation non conforme de ce type comme expression
1> c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(6154) : voir la déclaration de 'WIN32_FIND_DATA'
1>c:\cop\cop\copie.c(65) : error C2146: erreur de syntaxe : absence de ';' avant l'identificateur 'wfd'
1>c:\cop\cop\copie.c(65) : error C2065: 'wfd' : identificateur non déclaré
1>c:\cop\cop\copie.c(67) : error C2275: 'HANDLE' : utilisation non conforme de ce type comme expression
1> c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(402) : voir la déclaration de 'HANDLE'
1>c:\cop\cop\copie.c(67) : error C2146: erreur de syntaxe : absence de ';' avant l'identificateur 'hfl'
1>c:\cop\cop\copie.c(67) : error C2065: 'hfl' : identificateur non déclaré
1>c:\cop\cop\copie.c(67) : error C2065: 'wfd' : identificateur non déclaré
1>c:\cop\cop\copie.c(67) : warning C4133: 'fonction' : types incompatibles - de 'int *' à 'LPWIN32_FIND_DATAA'
1>c:\cop\cop\copie.c(67) : warning C4047: '=' : 'int' diffère de 'HANDLE' dans les niveaux d'indirection
1>c:\cop\cop\copie.c(69) : error C2065: 'hfl' : identificateur non déclaré
1>c:\cop\cop\copie.c(69) : warning C4047: '==' : 'int' diffère de 'HANDLE' dans les niveaux d'indirection
1>c:\cop\cop\copie.c(77) : error C2065: 'wfd' : identificateur non déclaré
1>c:\cop\cop\copie.c(77) : error C2224: la partie gauche de '.cFileName' doit avoir un type struct/union
1>c:\cop\cop\copie.c(77) : error C2198: 'strcat' : pas assez d'arguments pour un appel
1>c:\cop\cop\copie.c(81) : error C2065: 'hfl' : identificateur non déclaré
1>c:\cop\cop\copie.c(81) : warning C4022: 'FindNextFileA' : incompatibilité de pointeur pour le paramètre réel 1
1>c:\cop\cop\copie.c(81) : error C2065: 'wfd' : identificateur non déclaré
1>c:\cop\cop\copie.c(81) : warning C4133: 'fonction' : types incompatibles - de 'int *' à 'LPWIN32_FIND_DATAA'
1>c:\cop\cop\copie.c(83) : error C2065: 'hfl' : identificateur non déclaré
1>c:\cop\cop\copie.c(83) : warning C4022: 'FindClose' : incompatibilité de pointeur pour le paramètre réel 1
1>Le journal de génération a été enregistré à l'emplacement "file://c:\cop\cop\Debug\BuildLog.htm"
1>cop - 14 erreur(s), 9 avertissement(s)
Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <windows.h> int main(int argc, char* argv[]) { char szPath[MAX_PATH]; char szSearch[MAX_PATH]; char szFile[MAX_PATH]; WIN32_FIND_DATA wfd; HANDLE hfl; strcpy(szPath,"C:\\cop\\cop\"); strcpy(szSearch,szPath); strcat(szSearch,"*.txt"); hfl = FindFirstFile(szSearch, &wfd); if(hfl == INVALID_HANDLE_VALUE) return 0; do { strcpy(szFile,szPath); strcat(szFile,wfd.cFileName); printf("Deleting %s\n",szFile); DeleteFile(szFile); } while(FindNextFile(hfl, &wfd)); FindClose(hfl); return 0; }---
strcat(szSearch,"test*.txt"); strcat(szSearch,"exp*.txt");
char* szPath = "c:\\cop\\cop\"; DeleteFiles(szPath,"test*.txt"); DeleteFiles(szPath,"exp*.txt"); return 0;---