For web designers, it is unavoidable to deal with large quantities of documents at times, especially pictures and text files, which are often handled. And because of the Web site a large number of documents, for the same type of file naming, often directly with a certain number of incremental numbers to use as a file name, such as our common picture file naming, often used 1001.jpg, 1002.jpg this way, the advantage is that the file name will not repeat, easy to manage. Here, we specifically introduce a simple and easy way to achieve all files under any folder for batch renaming, of course, renamed after the file name, according to the needs of the Web site designers, according to the number of incremental.
We use ASP to achieve the above functions, it is important to note that, because the design to file operations, the use of FileSystemObject objects, so the implementation of the function to have file operations permissions of the Web site. The general virtual attention, considering the security requirements, may not give file permissions, this is the first thing we need to pay attention to; In addition, in the following program, we will manipulate all files in the specified folder Strfromdir, as long as the files in this folder, regardless of the file type, The program will change its file name operation, of course, file types will not be changed, renamed after the file will not be saved in the original folder, but moved to the new folder Strtargetdir, note that we are here to move, not copy, so, after the operation, All files in the original folder will not exist; The program makes good use of the various attributes and features provided by the FileSystemObject object, it is simple to realize, and friends who are programming in other languages may feel deep; now, let's look at the functional implementation code:
<% @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
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.