Using ASP to implement the code of renaming files in bulk

Source: Internet
Author: User
<% @LANGUAGE = VBSCRIPT%>
<%option explicit%>
<%
' Rename the file name in the folder and move all the files to the new folder in the following batch;
Response.Write "Response.Write "<title> Batch file Rename </title>" & VbCrLf
Response.Write "' Variable description
Dim gbolgoprocedure
Dim Strfromdir ' source folder
Dim Strtargetdir ' destination folder
Dim OBJFS
Dim Objrootfolder
Dim objfile
Dim Strfilenamelen
Dim Strprevfilename
Dim strfileext ' file name extension
Dim Strfilenamecount
Dim Strnewfilename
Dim strrealcount ' Number of files processed

Gbolgoprocedure = False

' If you click on the Start button, do the following
If (Request.Form ("Gobutton")) = "Start" Then

' Specify source folder, destination folder

Strfromdir = "D:test\"
Strtargetdir = "D:\test1\"

' Set the number of processed files to 0

Strrealcount = 0

Set OBJFS = Server.CreateObject ("Scripting.FileSystemObject")

Set Objrootfolder = Objfs.getfolder (Strtargetdir)
' The filename is set to 100001, indicating that the filename will be from 100001
' Start, gradually increase, can be set according to need;
Strfilenamecount = 100001
For each objfile in Objrootfolder.files
' For specific files, no processing, can be set according to need;
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 & "> moved and renamed as:" &strTargetDir& strnewfilename ; "<br>" & VbCrLF
Strfilenamecount = Strfilenamecount + 1
Strrealcount = Strrealcount + 1

Next

Response.Write "<p> <b> is handled altogether:" & (Strrealcount) & "Files </B>" & VbCrLf

Set Objrootfolder = Nothing
Set OBJFS = Nothing

Gbolgoprocedure = True

End If

If gbolgoprocedure Then
Response.Write ("<p> <b> Bulk file 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 bulk move and rename the file </b> </center>") & VbCrLf
End If

Response.Write "</body>" & VbCrLf & "
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.