功能:将当前文件夹下面所有的.ans文件改成同名的.out文件
#include<iostream>
#include<io.h>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<dir.h>
using namespace std;
string path;
const int N(100);
string oldname[N],newname[N];
int main()
{
path=getcwd(NULL,0);
if (path=="") return -1;
_finddata_t fileinfo;
long handle;
string temp=path+"\\*.ans";
handle=_findfirst(temp.c_str(),&fileinfo); //查找到第一个文件,文件信息存入fileinfo
if (handle==-1) return -1; //-1表示未找到,0表示找到
int n(0);
do{
oldname[n]=fileinfo.name;
newname[n]=fileinfo.name;
n++;
}while (_findnext(handle,&fileinfo)==0);
int k,len;
for (int i=1;i<=n;i++)
{
k=newname[i-1].size();
newname[i-1].replace(k-4,4,".out"); //后缀名改为.out
temp="ren "+oldname[i-1]+" "+newname[i-1];
//cout<<temp<<" ok"<<endl;
system(temp.c_str());
}
_findclose(handle);
//system("pause");
return 0;
}
posted on 2013-11-26 17:20
龙在江湖 阅读(237)
评论(0) 编辑 收藏 引用 所属分类:
C++