下面是一个简单的办法,考虑到所有的文件将被命名为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