美剧,电影等命名问题程序

我们经常下载一下美剧,有好多剧集,有很多收藏者收藏时发现文件名中有很多广告宣传信息,我特意写了一个程序,解决这一个问题,程序有以下功能:

1.删除文件中的特定字符

2.插入特定文件字符

3.重命名文件名

4.列出所有文件

注意及使用方法:

1.本程序采用codeblocks GCC编译器编译
2.运行时需将libgcc_s_dw2-1.dll 和 libstdc++-6.dll 放入C:\Windows下
3.将命名神器.exe 放入需处理的文件件内,程序会默认对当前文件夹内的所有文件(不包括子文件夹和子文件内的文件)进行处理
4.按程序提示操作即可

附件地址:http://download.csdn.net/detail/zhuihunmiling/9388595

警告:本计算机程序受著作权法和国际条约保护,如未经授权而擅自复制或传播本程序,,将受到严厉的民事制裁和刑事制裁,并将在法律许可的最大程度内受到起诉。

/**
*追魂密令工作室倾情编制
*zhuihunmiling@sina.com
*/
#include<iostream>
#include <dir.h>
#include<stdlib.h>
#include <windows.h>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define MAXPATH 255
#define MAXSIZE 255
bool compare(string s1,string s2)
{
    if(s1.size()<s2.size()) return true;
    else if(s1.size()==s2.size()&&s1<s2) return true;
    return false;
}
string getfilelist(string path)
{
    string strs="";
    long hFile = 0;
    struct _finddata_t fileInfo;
    string pathName=path, exdName;
    if ((hFile = _findfirst(pathName.append("\\*").c_str(), &fileInfo))==-1)
    {
        return "";
    }
    while (_findnext(hFile, &fileInfo) == 0)
    {

        string filename=fileInfo.name;
        if(fileInfo.attrib&_A_SUBDIR)continue;
        if(filename.find(".exe")<255) continue;
        strs=strs+filename+",";
    }
    _findclose(hFile);

    string sortstr[MAXSIZE];
    string s_all=strs;
    int n=0;
    while((s_all.find_first_of(",")>0&&s_all.find_first_of(",")<s_all.size()))
    {
        string filename=s_all.substr(0,s_all.find_first_of(","));
        sortstr[n]=filename;
        n++;
        s_all=s_all.substr(s_all.find_first_of(",")+1,s_all.size());
    }
    cout<<n<<endl;
    sort(sortstr,sortstr+n,compare);
    strs="";
    for(int i=0;i<n;i++)
        strs=strs+sortstr[i]+",";


    return strs;
}

void display_file_list(string path)
{
    string s_all=getfilelist(path);
    while((s_all.find_first_of(",")>0&&s_all.find_first_of(",")<s_all.size()))
    {
        string filename=s_all.substr(0,s_all.find_first_of(","));
        cout<<filename<<endl;
        s_all=s_all.substr(s_all.find_first_of(",")+1,s_all.size());
    }
}

int deletestr(string path,string s_delete)
{
    int countn=0;
    string s_all=getfilelist(path);
    while(s_all.find_first_of(",")>=0&&s_all.find_first_of(",")<s_all.size())
    {
        //==============
        string filename=s_all.substr(0,s_all.find_first_of(","));
        if(filename.find(s_delete)>=0&&filename.find(s_delete)<filename.size())
        {
            string source=path+"\\"+filename;
            filename.erase(filename.find(s_delete),s_delete.size());
            if(rename(source.c_str(),filename.c_str())!=-1)
            {
                countn++;
                cout<<"rename file:"<<countn<<endl;
            }
        }
        s_all=s_all.substr(s_all.find_first_of(",")+1,s_all.size());
    }
    return countn;
}
int renamefile(string path,string regulation)
{
    if(regulation.find_first_of("#")<0||regulation.find_first_of("#")>=regulation.size())
    {
        cout<<"没有找到#位置!"<<endl;
        return 0;
    }

    display_file_list(path);
    cout<<"将按此顺序重命名影视?(Y/N)";
    char c;
    cin>>c;
    if(c!='Y'&&c!='y') return 0;
    int countn=0;
    int i=1;
    string s_all=getfilelist(path);
    while(s_all.find_first_of(",")>=0&&s_all.find_first_of(",")<s_all.size())
    {
        string filename=s_all.substr(0,s_all.find_first_of(","));
        string source=path+"\\"+filename;
        char c[8];
        sprintf(c,"%02d",i);
        string t_regu=regulation;
        t_regu.replace(t_regu.find_first_of("#"),1,c);
        if(rename(source.c_str(),t_regu.c_str())!=-1)
        {
            countn++;
            i++;
            cout<<"rename file:"<<countn<<endl;
        }
        else cout<<"shibai"<<endl;
        s_all=s_all.substr(s_all.find_first_of(",")+1,s_all.size());
    }
    return countn;
}
int add_str2file(string path,string add_str,char c)
{
    int countn=0;
    string s_all=getfilelist(path);
    while(s_all.find_first_of(",")>=0&&s_all.find_first_of(",")<s_all.size())
    {
        //==============
        string filename=s_all.substr(0,s_all.find_first_of(","));
        string source=path+"\\"+filename;

        if(c=='y'||c=='Y') filename.insert(0,add_str);
        else filename.insert(filename.find_last_of("."),add_str);


        if(rename(source.c_str(),filename.c_str())!=-1)
        {
            countn++;
            cout<<"rename file:"<<countn<<endl;
        }

        s_all=s_all.substr(s_all.find_first_of(",")+1,s_all.size());
    }




    return countn;
}

void display()
{
    cout<<"==========追魂密令工作室倾情编制=============="<<endl;
    cout<<"==========zhuihunmiling@sina.com=============="<<endl;
    cout<<"请选择:"<<endl;
    cout<<"1:删除文件中的字符"<<endl;
    cout<<"2:重命名文件"<<endl;
    cout<<"3:输出当前文件列表"<<endl;
    cout<<"4:增加自定义字符串"<<endl;
    cout<<"0:退出"<<endl<<endl;
    cout<<":";
}
int main()
{
    char path[MAXPATH];
    getcwd(path,MAXPATH);

    display();
    int myselect=0;
    cin>>myselect;

    while(myselect!=0)
    {
        string s_all="";
        char c='y';
        switch(myselect)
        {
            case 1:
                cout<<"请输入要删除的字符串_:";
                getchar();
                getline(cin,s_all);
                cout<<"File renamed number:"<<deletestr(path,s_all)<<endl;
            break;
            case 2:
                cout<<"请输入要重命名的规则,用#表示剧集号_:";
                getchar();
                getline(cin,s_all);
                cout<<"File renamed number:"<<renamefile(path,s_all)<<endl;
            break;
            case 3:
                display_file_list(path);
            break;
            case 4:
                cout<<"请输入要增加的字符串_:";
                getchar();
                getline(cin,s_all);
                cout<<"输入Y/y在最前面添加,否则在最后添加_:";
                cin>>c;
                cout<<"File renamed number:"<<add_str2file(path,s_all,c)<<endl;
            break;
            default:
                cout<<"请重新选择"<<endl;
            break;
        }
        cout<<endl;
        display();
        cin>>myselect;
    }
    system("pause");
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值