Salut,
J'aimeris savoir si il y a une commande en C qui permet de copier un fichier d'un dossier quelconque, vers un autre dossier. Sans avoir un faire un appel systeme du genre
system("copy ...");
8)
@+
Version imprimable
Salut,
J'aimeris savoir si il y a une commande en C qui permet de copier un fichier d'un dossier quelconque, vers un autre dossier. Sans avoir un faire un appel systeme du genre
system("copy ...");
8)
@+
Sous Windows, tu peux essayer la fonction CopyFile:
Code:
1
2
3
4
5 BOOL CopyFile( LPCTSTR lpExistingFileName, // address of name of an existing file LPCTSTR lpNewFileName, // address of filename to copy to BOOL bFailIfExists // flag for operation if file exists );
tu peut aussi utiliser movefile
Pour te perfectionner en C, lire les tutoriels et cours de formation pour apprendre C : http://c.developpez.com/cours/Citation:
The MoveFile function renames an existing file or a directory (including all its children).
BOOL MoveFile(
LPCTSTR lpExistingFileName, // address of name of the existing file
LPCTSTR lpNewFileName // address of new name for the file
);
Parameters
lpExistingFileName
Points to a null-terminated string that names an existing file or directory.
lpNewFileName
Points to a null-terminated string that specifies the new name of a file or directory. The new name must not already exist. A new file may be on a different file system or drive. A new directory must be on the same drive.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Merci pour l'info. :D
Voici une fonction toute bête qui le fait :
Détails dans les cours et tutoriels pour bien apprendre la programmation C : http://c.developpez.com/cours/Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 #include <stdio.h> /* perror */ #include <fcntl.h> /* open */ #include <string.h> /* strcmp strcpy malloc */ #include <unistd.h> /* close read write */ int file_copy ( char * source, char * dest) { int src,dst,n; char buffer[512]; if ( ( src = open ( source, O_RDONLY) ) == -1 ) { perror ( "source"); return -1; } if ( ( dst = open ( dest, O_WRONLY|O_TRUNC|O_CREAT, 0666) ) == -1 ) { perror ( "destination"); close ( src); return -1; } while ( ( n = read ( src, buffer, 512) ) > 0 ) { if ( n != write ( dst, buffer, n) ) { return -1; } } if ( n < 0 ) { return -1; } close ( src); close ( dst); return 0; }