本文介绍了通过添加增量编号创建唯一的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果存在先前编号的文件名,我正在尝试增加文件名.

I'm trying to increment file names if a previously numbered one exists.

例如,它应该检查Example.csv"是否存在.如果是这样,新文件应命名为Example2.csv",然后是Example3.csv"、Example4.csv"等等.到目前为止,这是我的代码:

For example, it should check if "Example.csv" exists. If so, the new file should be called "Example2.csv", then "Example3.csv", "Example4.csv" and so on. Here's my code so far:

$fileNum = 2
; The $month variable is defined earler in the script but I'll define another var for this example
$month = "January"
If FileExists("Emissions Log - " & $month & ".csv") Then
    If FileExists("Emissions Log - " & $month & $fileNum & ".csv") Then
        $fileNum += 1
        $file = FileOpen("Emissions Log - " & $month & $fileNum & ".csv", 1)
    Else
        $file = FileOpen("Emissions Log - " & $month & $fileNum & ".csv", 1)
    EndIf
Else
    $file = FileOpen("Emissions Log - " & $month & ".csv", 1)
EndIf

推荐答案

为此,您必须循环文件名.

In order to do that, you must loop the filenames.

$month = "January"

For $i = 0 To 1000 ;max file versions is set to 1000

    If $i = 0 Then
        $num = ''
    Else
        $num = $i
    EndIf

    If Not FileExists("Emissions Log - " & $month & $num & ".csv") then
        $file = FileOpen("Emissions Log - " & $month & $num & ".csv", 1)
        ExitLoop
    EndIf
Next

这篇关于通过添加增量编号创建唯一的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:22