<% @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