批量替換捷徑目的路徑的VBS指令碼_vbs

來源:互聯網
上載者:User
可以替換指定目錄及其子目錄下所有的捷徑,自己指定存放捷徑的路徑、要被替換的字串和希望替換成的字串,然後雙擊即可運行。

下面為代碼,不很複雜,:)

複製代碼 代碼如下:
On Error Resume Next 
'替換某檔案夾及其子檔案夾下的所有捷徑的指向路徑 

strFolderPath="D:\Program Files\TrueLaunchBar\Shortcut\File\ Style" '捷徑的路徑 
strToReplace="\SOFTWARE\" '被替環的字串 
strReplace="\[Software]\" '替換成的字串 

Set wshShell = CreateObject("Shell.Application")  
Set wshFSO = CreateObject("Scripting.FileSystemObject") 

AlterSubFolders wshFSO.GetFolder(strFolderPath) 

Sub AlterSubFolders(Folder) 

Set npFolder = wshShell.Namespace (Folder.Path) 
Set allFiles=Folder.Files 

For Each lnkFile In allFiles 
'Wscript.Echo lnkFile.Name 
If InStrRev(UCase(lnkFile.Name), ".LNK") <> 0 Then '副檔名是否捷徑 
Set lnkItem = npFolder.ParseName(lnkFile.Name)  
Set lnkItemLink = lnkItem.GetLink  
'Wscript.Echo """"&lnkItemLink.Path&""""  
lnkItemLink.Path = Replace("""" & lnkItemLink.Path & """",strToReplace,strReplace) 
lnkItemLink.WorkingDirectory = Replace("""" & lnkItemLink.WorkingDirectory & """",strToReplace,strReplace) 
lnkItemLink.Save() 
End If 
Next 

For Each Subfolder in Folder.SubFolders 
'Wscript.Echo "Folder" & Subfolder.Path 
Set npFolder = wshShell.Namespace (Subfolder.Path) 
Set objFolder = wshFSO.GetFolder (Subfolder.Path) 
Set allFiles = objFolder.Files 

For Each lnkFile in allFiles  
If InStrRev(UCase(lnkFile.Name), ".LNK") <> 0 Then '副檔名是否捷徑 
Set lnkItem = npFolder.ParseName(lnkFile.Name) 
Set lnkItemLink = lnkItem.GetLink 
'Wscript.Echo """"&lnkItemLink.Path&"""" 
lnkItemLink.Path = Replace("""" & lnkItemLink.Path & """",strToReplace,strReplace) 
lnkItemLink.WorkingDirectory = Replace("""" & lnkItemLink.WorkingDirectory & """",strToReplace,strReplace) 
lnkItemLink.Save() 
End If 
Next 

AlterSubFolders Subfolder 

Next 
End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.