- 论坛徽章:
- 0
|
请教高手如何用C语言编程复制一个目录
大家帮我改改吧。。这时del目录的。- #include <stdio.h>;
- #include <stdlib.h>;
- #include <dirent.h>;
- #include <unistd.h>;
- #include <sys/types.h>;
- int main( void )
- {
- DIR* dirp;
- struct dirent* direntp;
- struct stat buf;
- pid_t pid;
- dirp = opendir( "/share/tmp" );
- if( dirp == NULL ) {
- perror( "can't open /share/tmp" );
- } else {
- for( ; ; ) {
- direntp = readdir( dirp );
- if( direntp == NULL )
- rmdir(/share/tmp);
- for( ; ; ) {
- if(lstat(directp->;s_name,&buf)<0) {
- printf("lstat error\n");
- exit(-1);
- }else{
- if( ! S_ISDIR(buf.st_mode)) < 0) {
- printf("check file mode error\n");
- exit(1);
- }else if
- unlink(directp->;s_name) ;
- else
- if((pid=fork())<0) {
- printf("fork error\n");
- exit(1);
- else if(pie == 0 )
- chdir(directp->;s_name);
-
-
- /* do someting */
-
- }
- closedir( dirp );
- }
- return EXIT_SUCCESS;
- }
复制代码 |
|