按修改時間重新命名批處理 C

2021-08-28 03:11:56 字數 1665 閱讀 4674

按修改時間重新命名批處理(c++)實現步驟:

1.獲取指定目錄下所有檔案檔名

2.獲取所有檔案建立時間,修改時間,訪問時間

3.根據檔案時間排序

4.根據排序重新命名檔案

1.獲取指定目錄下所有檔案檔名 

std::vectorfiles;  //記錄檔名

void getpathfile(cstring strdir)

tempfind.close();

}

2.獲取所有檔案建立時間,修改時間,訪問時間

systemtime stlocal,stlocal1,stlocal2;

void getfiletime(cstring strfilepath )

zeromemory(&stlocal, sizeof(systemtime));

filetimetosystemtime(&ftmodify, &stlocal);//修改時間

zeromemory(&stlocal1, sizeof(systemtime));

filetimetosystemtime(&ftcreate, &stlocal1);//建立時間

zeromemory(&stlocal2, sizeof(systemtime));

filetimetosystemtime(&ftaccess, &stlocal2);//訪問時間

closehandle(hfile);

}long long systemtimetoseconds(systemtime& st)//將時間轉換為秒

3.根據檔案時間排序

void quick_sort(long long *a, int *id, int m)//輸出索引

id[i] = tmp;

quick_sort(a, id, i);

quick_sort(a, id + i + 1, m - i - 1);

}}

4.根據排序重新命名檔案

bool renamefile(cstring strsrc, cstring strnew)

catch(cfileexception* pex )

return nret==0;

}

完整使用

void batch()

{ updatedata(true);

files.clear();

getpathfile(filepathstr);//獲取路徑下指定型別的檔名

long long *filetime=new long long[files.size()*sizeof(long long)];

memset(filetime,0,sizeof(long long));

int *idx=new int[files.size()*sizeof(int)];

memset(idx,0,sizeof(int));

for (int i=0;i

重新命名批處理python指令碼

將copy of bmp或者copy of copy of bmp 此類檔案統一命名為 0.bmp 或者 00.bmp等格式,後面的0的個數代表 bmp出現的次數 1。ctwwnky寫了個下面的小指令碼 複製 如下 import os 這個程式是用來將檔名改名,因為在資料夾裡面有很多copy of ...

BAT批處理 檔案重新命名

1.bat重新命名檔案 ren 111.txt 222.doc 解釋 將111.txt 命名為222.doc 2.迴圈重新命名乙個資料夾下的所有結尾為xls的檔案,前加上a for f i in dir b txt do ren i a i 3.在原檔名前面加當前系統日期格式yyyymmdd ech...

重新命名批處理的python指令碼

採集的視網膜影象放在乙個資料夾下,分類十分混亂,出現了乙個檔案多次出現的情況,因此寫指令碼將copy of bmp或者copy of copy of bmp 此類檔案統一命名為 0.bmp 或者 00.bmp等格式,後面的0的個數代表 bmp出現的次數 1。網上有不少 url 教程 url 中沒有這...