用ASP實現遠程將檔案批量改名的代碼

來源:互聯網
上載者:User

<% @LANGUAGE = VBSCRIPT %>
<%Option Explicit%>
<%
'以下程式批量改名檔案夾中的檔案名稱,並將所有檔案移動到新的檔案夾;
Response.Write "<html>" & VbCrLf & "<head>" & VbCrLf
Response.Write "<title>批量檔案改名</title>" & VbCrLf
Response.Write "</head>" & VbCrLf & "<body>" & VbCrLf
' 變數說明
Dim gbolGoProcedure
Dim strFromDir '源檔案夾
Dim strTargetDir '目標檔案夾
Dim objFS
Dim objRootFolder
Dim objFile
Dim strFileNameLen
Dim strPrevFileName
Dim strFileExt '副檔名
Dim strFileNameCount
Dim strNewFileName
Dim strRealCount '處理的檔案數量

gbolGoProcedure = False

' 如果點擊了開始按鈕,進行以下處理
If (Request.Form("GoButton")) = " 開 始 " then

' 指定源檔案夾、目標檔案夾

 strFromDir = "D:test\"
 strTargetDir = "D:\test1\"

 ' 將處理檔案數量設定為0

 strRealCount = 0

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

 Set objRootFolder = objFS.GetFolder(strTargetDir)
 '檔案名稱的具體設定,這裡設定為100001,表明檔案名稱將從100001
 '開始,逐步遞增,可以根據需要設定;
 strFileNameCount = 100001
For each objFile in objRootFolder.Files
 '對於特定的檔案,不進行處理,可以根據需要設定;
 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 "源檔案: " &strFromDir&strPrevFileName & " > 移動並改名為: " &strTargetDir& strNewFileName & "<br>" & vbCrLF
 strFileNameCount = strFileNameCount + 1
 strRealCount = strRealCount + 1

Next

 Response.Write "<p><b>一共處理: " & (strRealCount) & " 個檔案</B>" & vbCrLf

 Set objRootFolder = Nothing
 Set objFS = Nothing

 gbolGoProcedure = True

End If

If gbolGoProcedure Then
 Response.Write("<p><b>批量檔案批量移動和改名</b>") & vbCrLf

Else
 Response.Write("<center><br><form method=""post"" action=""FileNameConverter.asp""  ID=form1 name=""form1"">") & vbCrLf
 Response.Write("<input type=""SUBMIT"" value="" 開 始 "" ID=""GoButton""  name=""GoButton"">") & vbCrLf
 Response.Write("</form>") & vbCrLf
 Response.Write("<p><b>點擊按鈕對檔案進行批量移動和改名</b></center>") & VbCrLf
End If

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

%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.