怎样在控制台中批量改文件名?
比如某个文件夹中有 一些文件,现在需要在所有的文件名后面加上扩展名htm...我试过了mv , rename 好像都不行啊?
而且在KDE文件管理器中也做不到...8-(
请问有没有类似win中TotalCommander那样的可以批量改名的东东? 写script吧,perl里面有很多文件操作的函数的 Oh~not that hard..Try this script
#!/bin/sh
for i in `echo *`
do
mv $i ${i}.htm #change your file name here!
done
如果文件名有空格,怎么办? 如果文件名有空格,怎么办?
Try this: it can change all file names incurrent directory.
#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;
}
如果文件名有空格,怎么办?
Try this: it can change all file names incurrent directory.
#include <dirent.h>
#include <string.h>
#include <stdio.h>
……
……
……
多谢多谢!
我打算把它段代码用python来重写一下,然后再使它支持命令行参数,这样便于控制后缀名。
还有,我想知道能不能就利用linux现有的基本程序来做到这点
页:
[1]