For website designers, it is often handled by a large number of files, especially pictures and some text files, especially pictures and some text files. Since the relationship between the website, the name of the same type of file is often used directly as a file name with a certain regular incremental number, for example, we often use 1001.jpg, 1002. JPG this way, this benefit is that the file name will not be repeated, easy to manage. Here, we specialize in a simple and easy way to realize all the files under any folder, of course, the file name after the rename will be based on the needs of the website designer, increment according to the number.
We use ASP to implement the above features, you need to note that because the design to file operation, use the FileSystemObject object, so the implementation of this feature is to be done in a website with file operation. General virtual attention, considering security requirements, may not give file existence, this is what we first need to pay; in addition, in the following program, we will operate all files in the specified folder strFromDir, as long as this file is The file in the clip, whether the file type is file type, of course, the file type does not change, the file after the rename, will not be saved in the original folder, but moves to new folders Strtargetdir, pay attention, we are moving here, not copy, so after operation, all files in the original folder will not exist; the program is good to use the various properties and features provided by the FileSystemObject object, simple when implementing Ming, friends who use other language programming may feel deep; now, let's see the functional implementation code:
<% @Language = VBScript%>
<% OPTION Explicit%>
<%
'The following programs batch the file name in the rename folder and move all files to a new folder;
Response.write "" & vbcrlf & "
" & vbcrlfResponse.write "
Response.write " head>" & vbcrlf & "
'Variable description
Dim gbolgoprocedure
DIM STROMDIR 'Source Folder
DIM STRTARGETDIR 'target folder
DIM OBJFS
Dim objrootfolder
DIM Objfile
DIM STRFILENAMELEN
DIM STRPREVFILENAME
DIM STRFILEXT 'File extension
DIM STRFILENAMECOUNT
DIM STRNEWFILENAME
Dim strreatalcount '
gbolgoprocedure = false
'If you click the start button, do the following
IF (Request.form ("GOBUTTON") = "start" THEN 'specified source folder, target folder
strfromdir = "D: Test /"
Strtargetdir = "D: / TEST1 /"
'Set the number of processes to 0
StrRealcount = 0
Set objfs = server.createObject ("scripting.filesystemObject")
Set objrootfolder = objfs.getfolder (Strtargetdir)
'The specific setting of the file name, here is set to 100001, indicating that the file name will be from 100001
'Start, gradually increment, can be set as needed;
Strfilenamecount = 100001
For Each Objfile in Objrootfolder.Files
'For a specific file, it is not processed, and it can be set as needed;
IF objfile.name = "thumbs.db" Then StrfileNameCount = STRFILENAMECUNT - 1
StrfilenameCount = STRFILENAMECUNT 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 "and renamed:" & Strtargetdir & StrnewFileName & "
" & vbrlf
StrfilenameCount = STRFILENAMECUNT 1
StrRealcount = STRREALCOUNT 1
NEXT
Response.write "
A total of:" & Strrealcount) & "File b>" & vbcrlf
Set objRootfolder = Nothing
Set objfs = Nothing
gbolgoprocedure = true
END IF
IF gbolgoprocedure dam
Response.write ("
bulk file batch movement and rename b>") & vbcrfelse
Response.write ("
Response.write (" ") & vbcrlf
Response.write (" form>") & vbcrlf
Response.write ("
Click the button to batch mobile and rename b>
END IF
Response.write " body>" & vbcrlf & " html>"
%>