收集了很图片, 文件名乱糟糟的, 所以有了下面的代码. 问题在注释那段, 很疑惑不解, 希望有谁能帮我解答一下, 感谢!
#include<stdio.h>
#include<string.h>
#include<dirent.h>
#include<unistd.h>
main(int argc, char **argv)
{
DIR *dir;
struct dirent *file;
char oldname[256];
int i = 'a', j = 'a';
char *tmp;
tmp = *++argv; //为什么我把这行删除, 再把下面的tmp改成*++argv就不行了呢, 这两种写法不是等价的吗?郁闷………~~~!
dir = opendir (tmp);
chdir (tmp);
while (file = readdir(dir)) {
strcpy (oldname, file->d_name);
if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0) {
while (j <= 'z') {
file->d_name[0] = i;
file->d_name[1] = j;
file->d_name[2] = '\0';
strcat (file->d_name, ".jpg");
rename (oldname, file->d_name);
j++;
break;
}
if (j > 'z') {
i++;
j = 'a';
}
}
}
closedir (dir);
} |