重命名美剧。。

美剧下载总是有一些前缀[xxxxxxxxxx],不方便看文件名

windows下又懒得弄python啥的,只好写了一个rename的,去掉前缀。。

 

 

假设编译好后的程序为 renameRMVB.exe用下面的批处理命令调用

 

for /f %i in ('dir *.rmvb /B ') do renameR 

 

Linux下就简单多了,直接bash

 

#!/bin/bash

for video in *.rmvb; do  

     newName=`echo $video | sed 's//[.*/]//'`

     mv $video $newName;

done

 

注意如果没有[]这样的开头结束的话,sed要专门处理中文则要要先设置LANG=C或者其他字符集,

对中文用[/080-xff]匹配双字节字符,(好像也有匹配utf8什么的,对应的locale要设置对)

 

下面是renameRMVB的源代码:

 

#include <iostream> #include <string> #include <cstdlib> #include <cctype> using namespace std; void renameRMVB(const char * filename, int indent) { string fileName(filename), newFileName; string cmd = "rename "; int pos = fileName.find("]"); if (pos != string::npos) { newFileName = fileName.substr(pos + indent + 1) ; cmd = cmd + filename + " " + newFileName; cout << cmd << endl; system( cmd.c_str() ); } } bool isNumber(const char * number) { bool ret = true; for (int i=0; number[i] != '/0'; i++) { if (!isdigit(number[i])) { ret = false; break; } } return ret; } int main(int argc, char* argv[]) { int ret = 0; if ((argc != 2) && (argc != 3)) { cout << "Usage : renameRMVB [FILENAME] [INDENT] " << endl; ret = -1; } else { if (argc == 2 ) { renameRMVB(argv[1], 0); } else { if (isNumber(argv[2])) renameRMVB(argv[1], atoi(argv[2])); else { cout << "Error : INDENT should be number, input is " << argv[2] << endl; ret = -1; } } } return ret; }  

 

 

你可能感兴趣的:(windows,python,String,video,cmd,System)