凤来仪

专业的计算机学习网站

首页 > ASP自动重命名同名新文件

ASP自动重命名同名新文件

点击:1107 发布时间:

ASP检查文件是否存在,并自动重命名相同名字的新文件

Function CheckFileExists(Folder,FileName)
  Folder=Server.Mappath(Folder)
  If Right(Folder,1)<>"/" Then Folder=Folder&"/"
  Set fso=Server.CreateObject("Scripting.FileSystemObject")
  If fso.FileExists(Folder&FileName) Then
    i=1
    msg=True
    Do While msg
      CheckFileExists = Replace(FileName,Right(FileName,4),"_" & i & Right(FileName,4))
      If not fso.FileExists(Folder&CheckFileExists) Then
        msg=False
      End If
      i=i+1
    Loop
  Else
    CheckFileExists=FileName
  End If
  Set fso=Nothing
End Function

Response.Write CheckFileExists(".","fso.asp") '其中的.表示当前文件夹。如果fso.asp存在,则返回fso_1.asp
Response.Write CheckFileExists("/news/","index.asp")