1. 程式人生 > >c++修改指定資料夾下所有副檔名

c++修改指定資料夾下所有副檔名

#include <io.h>  
#include <iostream>  
#include <cstring>  
#include <string>

using namespace std; 
//讀取資料夾設定
const string path = "D:\\pp\\";


int main(){  
    _finddata_t file;  
    long lf;  
    if((lf = _findfirst((path + "*.*").c_str(), &file))==-1)  
        cout
<<"Not Found!"<<endl; else{ // cout<<"file name list:"<<endl; while(_findnext( lf, &file)==0){ { string str=file.name; //修改副檔名為.jpeg str += ".jpeg"; //重新命名檔案 if
(rename((path + string(file.name)).c_str(), (path + str).c_str()) == 0) { //cout << "1" << endl; } } } } _findclose(lf); return 0; }