簡體   English   中英

如何使用腳本重命名成對的文件

[英]how to rename files in a pair with a script

我在一個文件夾中有 10 個 pdf 文件,我試圖找到一種方法來使用腳本將它們重命名為成對的文件,使其看起來像這樣

file131.pdf = order_receipt_1000.pdf
file304.pdf = invoice_1000.pdf
file542.pdf = order_receipt_1001.pdf
file194.pdf = invoice_1001.pdf

接下來的 8 個以此類推

也許這給了你一個很好的起點。 語言是Autoit。 ( www.autoitscript.com )

目前,該腳本會查看為 *pdf 文件保存的文件夾。 然后創建一個包含找到的文件的新數組,第二列包含創建文件的時間。 之后,最后一個 For 循環將文件重命名為兩個文件的塊。

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $aFileList = _FileListToArray(@ScriptDir, '*.pdf', Default, True) ; change @scriptDir to the path you need
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf

    _ArrayDisplay($aFileList, "Files FOUND")

    Local $a[UBound($aFileList)][2]

    For $i = 0 To UBound($aFileList) - 1
        $a[$i][0] = $aFileList[$i]
        $a[$i][1] = FileGetTime($aFileList[$i], $FT_CREATED, $FT_STRING) ; change FT_CREATED to what you need (created, modified, ...)
    Next

    _ArraySort($a, 0, 0, 0, 1)

    _ArrayDisplay($a, "Sorted FileList")
    Local $startcount = 1000, $y = 0

    For $i = 1 To UBound($a) - 1 Step 2
        FileMove($a[$i][0], 'order_receipt_' & $startcount + $y & '.pdf')
        FileMove($a[$i + 1][0], 'invoice_' & $startcount + $y & '.pdf')
        $y += 1
    Next
EndFunc   ;==>Example

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM