<% @LANGUAGE = VBSCRIPT %>
<%Option Explicit%>
<%
'The following program batch renames the file names in the folder and moves all files to a new folder;
Response.Write "<html>" & VbCrLf & "<head>" & VbCrLf
Response.Write "<title>Batch file name change</title>" & VbCrLf
Response.Write "</head>" & VbCrLf & "<body>" & VbCrLf
' Variable description
Dim gbolGoProcedure
Dim strFromDir'Source folder
Dim strTargetDir'Target folder
Dim objFS
Dim objRootFolder
Dim objFile
Dim strFileNameLen
Dim strPrevFileName
Dim strFileExt 'File extension
Dim strFileNameCount
Dim strNewFileName
Dim strRealCount 'Number of files processed
gbolGoProcedure = False
'If the Start button is clicked, perform the following processing
If (Request.Form("GoButton")) = "Start" then
' Specify the source folder and the destination folder
strFromDir = "D:test/"
strTargetDir = "D:/test1/"
' Set the number of processing files to 0
strRealCount = 0
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFS.GetFolder(strTargetDir)
'The specific settings of the file name, set to 100001 here, indicating that the file name will be from 100001
'Start, increment gradually, can be set as needed;
strFileNameCount = 100001
For each objFile in objRootFolder.Files
'For specific files, they are not processed and can be set as needed;
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
strPrevFileName = objFile.Name
strNewFileName = strFileNameCount & strFileExt
objFile.Move strTargetDir & strNewFileName
Response.Write "Source File: " &strFromDir&strPrevFileName & " > Move and change it to: " &strTargetDir& strNewFileName & "<br>" & vbCrLF
strFileNameCount = strFileNameCount + 1
strRealCount = strRealCount + 1
Next
Response.Write "<p><b> Total processing: " & (strRealCount) & " files </B>" & vbCrLf
Set objRootFolder = Nothing
Set objFS = Nothing
gbolGoProcedure = True
End If
If gbolGoProcedure Then
Response.Write("<p><b>Batch file batch move and rename </b>") & vbCrLf
Else
Response.Write("<center><br><form method=""post"" action=""FileNameConverter.asp"" ID=form1 name=""form1""">") & vbCrLf
Response.Write("<input type=""SUBMIT"" value="" Start"" ID=""GoButton"" name=""GoButton""">") & vbCrLf
Response.Write("</form>") & vbCrLf
Response.Write("<p><b>Click the button to batch move and rename the file </b></center>") & VbCrLf
End If