|
发表于 2003-8-12 11:26:28
|
显示全部楼层
[quote:09aafeaa76="wanghixxyy"]如果文件名有空格,怎么办?[/quote]
Try this: it can change all file names in current directory.
[code:1]
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define SUFFIX ".html"
int main( int argc, char **argv )
{
DIR *dir;
struct dirent *dp;
char s[255];
if ( ( dir = opendir(".") ) == NULL )
perror("opendir");
while ( ( dp = readdir(dir) ) != NULL )
{
if ( strcmp( dp->d_name , "." ) == 0 ||
strcmp( dp->d_name, ".." ) == 0 )
continue;
strcpy( s, dp->d_name );
strcat( s, SUFFIX );
rename( dp->d_name, s );
printf( "%s ==> %s\n", dp->d_name, s );
}
closedir(dir);
return 0;
}
[/code:1] |
|