<% @LANGUAGE = VBSCRIPT %> <%Option Explicit%> <% '以下程序批量改名文件夾中的文件名,并將所有文件移動到新的文件夾; Response.Write "<html>" VbCrLf "<head>" VbCrLf Response.Write "<title>批量文件改名</title>" VbCrLf Response.Write "</head>" VbCrLf "<body>" VbCrLf ' 變量說明 Dim gbolGoProcedure Dim strFromDir '源文件夾 Dim strTargetDir '目標文件夾 Dim objFS Dim objRootFolder Dim objFile Dim strFileNameLen Dim strPrevFileName Dim strFileExt '文件擴展名 Dim strFileNameCount Dim strNewFileName Dim strRealCount '處理的文件數量
gbolGoProcedure = False
' 如果點擊了開始按鈕,進行以下處理 If (Request.Form("GoButton")) = " 開 始 " then
' 指定源文件夾、目標文件夾
strFromDir = "D:test\" strTargetDir = "D:\test1\"
' 將處理文件數量設置為0
strRealCount = 0
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFS.GetFolder(strTargetDir) '文件名的具體設置,這里設置為100001,表明文件名將從100001 '開始,逐步遞增,可以根據需要設置; strFileNameCount = 100001 For each objFile in objRootFolder.Files '對于特定的文件,不進行處理,可以根據需要設置; If objFile.Name = "Thumbs.db" then strFileNameCount = StrFileNameCount - 1 strFileNameCount = strFileNameCount + 1 Next
Set objRootFolder = objFS.GetFolder(strFromDir) For each objFile in objRootFolder.Files strFileNameLen = Len (objFile.Name) If Mid (objFile.Name,(strFileNameLen - 3),1) = "." then strFileExt = right(objFile.Name, 4) Else strFileExt = right(objFile.Name, 5) End If