概述
可以替换指定目录及其子目录下所有的快捷方式,自己指定存放快捷方式的路径、要被替换的字符串和希望替换成的字符串,然后双击即可运行。
下面为代码,不很复杂,:)
复制代码 代码如下:
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
最后
以上就是典雅含羞草为你收集整理的批量替换快捷方式目的路径的VBS脚本的全部内容,希望文章能够帮你解决批量替换快捷方式目的路径的VBS脚本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复