Code for renaming objects in batches remotely using ASP

Source: Internet
Author: User

<% @ LANGUAGE = VBSCRIPT %>
<% Option Explicit %>
<%
'The following program batch rename the file names in the folder and move all the files to the new folder;
Response. Write "Response. Write "<title> batch file renaming </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 extension
Dim strFileNameCount
Dim strNewFileName
Dim strRealCount 'number of processed files

GbolGoProcedure = False

'If you click the start button, perform the following operations:
If (Request. Form ("GoButton") = "start" then

'Specify the source folder and target 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)
'Specific settings of the file name. Here it is set to 100001, indicating that the file name will be from 100001
'Starts and increments gradually. You can set it as needed;
StrFileNameCount = 100001
For each objFile in objRootFolder. Files
'The specific files 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 rename 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 movement and renaming </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 move and rename the file in batches </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.