zoukankan      html  css  js  c++  java
  • AutoTidyMyFiles

    大学时爱看电影,

    记录了很多截图文件,

    今日闲来无事,

    写了一个,正好记录下

    AutoTidyMyFiles

    作用是将多个目录下的同一部电影的截图文件统一剪切到自己电影名的目录下,

    这里有很多特殊情况的特殊处理,

    且目录,文件名需要整理

    推荐使用TotalCommander和正则表达式来进行处理:

      1// AutoTidyMyFiles.cpp : Defines the entry point for the console application.
      2//
      3  4 #include "stdafx.h"
      5 #include "windows.h"
      6 #include <iostream>
      7 #include <string>
      8 #include <vector>
      9 
     10 using namespace std;
     11 
     12 string GOutPutDir;
     13 int GCount;
     14 struct sFile
     15 {
     16     string strShortName;
     17     string strDir;
     18 };
     19 
     20 void AutoTidy(char * lpPath)
     21 {
     22     char szFind[MAX_PATH];
     23     char szFile[MAX_PATH];
     24     vector<sFile > vecNameList; 
     25     vector<sFile >::iterator iter;
     26     string strTarget;
     27     string strShortName;
     28     long result;
     29     WIN32_FIND_DATA FindFileData;
     30 
     31     strcpy(szFind,lpPath);
     32     strcat(szFind,"\\*.*");
     33 
     34     HANDLE hFind=::FindFirstFile(szFind,&FindFileData);
     35     if(INVALID_HANDLE_VALUE == hFind)    
     36         return;
     37     while(TRUE)
     38     {
     39         if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
     40         {
     41             if(FindFileData.cFileName[0]!='.')
     42             {
     43                 strcpy(szFile,lpPath);
     44                 strcat(szFile,"\\");
     45                 strcat(szFile,FindFileData.cFileName);
     46                 AutoTidy(szFile);
     47             }
     48         }
     49         else
     50         {
     51             bool bNeedBuild=true;
     52             //cout << FindFileData.cFileName;
     53             strShortName=FindFileData.cFileName;
     54             strShortName=strShortName.substr(0,9);
     55             //确定当前文件具体地址
     56             strcpy(szFile,lpPath);
     57             strcat(szFile,"\\");
     58             strcat(szFile,FindFileData.cFileName);
     59             if( ! vecNameList.empty() )
     60             {
     61                 for( iter=vecNameList.begin();iter!=vecNameList.end();++iter )
     62                 {
     63                     if( iter->strShortName == strShortName )
     64                     {
     65                         strTarget=iter->strDir+FindFileData.cFileName;
     66                         //剪切过去
     67                         result=MoveFileA(szFile,strTarget.c_str() );
     68                         if0==result )
     69                             cout<<"==Failed toMoveFile:"<<FindFileData.cFileName<<endl;
     70                         bNeedBuild=false;
     71                     }
     72                 }
     73             }
     74             if( bNeedBuild )
     75             {
     76                 sFile tFile;
     77                 string sDir;
     78                 tFile.strShortName=strShortName;
     79                 //以找到的第一个文件作为文件名
     80                 sDir=FindFileData.cFileName;
     81                 sDir=sDir.substr(0,sDir.find_last_of("["));
     86                 tFile.strDir=GOutPutDir+string("/")+sDir+string("/");
     87                 //填入vecNameList
     88                 //建立一个目录 
     89                 result=CreateDirectoryA(tFile.strDir.c_str(),NULL);
     90                 //将自己剪切过去
     91                 strTarget=tFile.strDir+FindFileData.cFileName;
     92                 if0==result )
     93                 {
     94                     //直接放到根目录下
     95                     tFile.strDir=GOutPutDir;
     96                     cout<<"==*Failed to Build Dir:"<<sDir<<endl;
     97                 }
     98                 else
     99                 {
    100                     cout<<"==Build Dir:"<<sDir<<endl;
    101                     MoveFileA(szFile, strTarget.c_str());
    102                 }
    103                 vecNameList.push_back( tFile );
    104             }
    105         }
    106         if(!FindNextFile(hFind,&FindFileData))   
    107             break;
    108     }
    109     GCount+=vecNameList.size();
    110     FindClose(hFind);
    111 }
    112 
    113 int _tmain(int argc, _TCHAR* argv[])
    114 {
    115     GCount=0;
    116     char szDir[]="O:/The KMPlayer";
    117     GOutPutDir=szDir+string("2");
    118     AutoTidy(szDir);
    119     int i;
    120     cin>>i;
    121     return 0;
    122 }

  • 相关阅读:
    微服务、SpringCloud、k8s、Istio杂谈
    php环境安装
    最近重构公司消息服务的架构设计
    test
    博文目录(最新更新:2019.8.5)
    读过的书
    我在北京这几年(全)
    【原】深度学习的一些经验总结和建议 | To do v.s Not To Do
    如何高效利用一场技术分享?
    深度学习分布式训练及CTR预估模型应用
  • 原文地址:https://www.cnblogs.com/Zephyroal/p/2753073.html
Copyright © 2011-2022 走看看