批量替换快捷方式目的路径的VBS脚本
人气:0想了解批量替换快捷方式目的路径的VBS脚本的相关内容吗,在本文为您仔细讲解的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:批量替换快捷方式目的路径的VBS脚本,下面大家一起来学习吧。
可以替换指定目录及其子目录下所有的快捷方式,自己指定存放快捷方式的路径、要被替换的字符串和希望替换成的字符串,然后双击即可运行。 下面为代码,不很复杂,:)
复制代码 代码如下:
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
'替换某文件夹及其子文件夹下的所有快捷方式的指向路径
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
加载全部内容