下面是一個簡單的辦法,考慮到所有的文件將被命名爲numeric.jpg,你將不得不雖然建立自己的函數:
FileExists(Filename)
RenameFile(OriginalFilename,NewFilename)
<%
Input1 = Request.Form("file1")
Input2 = Request.Form("file2")
'gets digits only
Input1Digit = Left(Input1,Instr(Input1,"."))
Input2Digit = Left(Input2,Instr(Input2,"."))
'is file1 less than file2?
If Input1Digit < Input2Digit Then
'loop through the digits frontwards 1 to 5
For x = Input1Digit to Input2Digit
'if the first loop?
If cStr(x) = cStr(Input1Digit) Then
'see if file exists here
If FileExists(Input1) Then
FileRename(Input1, Input1 & ".temp") 'Rename the file here [From, To]
OriginalFileExists = True
Else
FileRename(Input1, Input1Digit & ".jpg"
OriginalFileExists = False
End If
'if not on the first loop?
Else
'did the original file exist '.temp'
If OriginalFileExists Then
NewFileName = cInt(x) - 1
Else
NewFileName = cInt(x)
End If
'rename each file here
RenameFile(x & ".jpg", NewFileName & ".jpg")
End If
Next
Else
'loop through the digits more to less 5 to 1
For x = Input1Digit to Input2Digit STEP -1
'if the first loop?
If cStr(x) = cStr(Input1Digit) Then
'see if file exists here
If FileExists(Input1) Then
FileRename(Input1, Input1 & ".temp") 'Rename the file here [From, To]
OriginalFileExists = True
Else
FileRename(Input1, Input1Digit & ".jpg"
OriginalFileExists = False
End If
'if not on the first loop?
Else
'did the original file exist '.temp'
If OriginalFileExists Then
NewFileName = cInt(x) + 1
Else
NewFileName = cInt(x)
End If
'rename each file here
RenameFile(x & ".jpg", NewFileName & ".jpg")
End If
Next
End If
%>
好循環對文件進行檢查,檢查其名稱並進行更改是唯一方法(或者將它們添加到可排序的集合中然後重命名)。因爲這是asp,那麼大概有一個人可能會觸發這個,所以如果他們都在同一時間做這件事情會發生什麼。也許在txt/xml/db中定義的固定名稱和順序會更好 – 2012-02-15 16:39:15
是的,我知道,但我有一項任務將此功能添加到甚至沒有數據庫的舊應用程序,並且他們使用了相應的數字文件...:/ – 2012-02-15 16:47:03