批量替换快捷方式目的路径的VBS脚本
程序员文章站
2022-08-28 10:55:35
可以替换指定目录及其子目录下所有的快捷方式,自己指定存放快捷方式的路径、要被替换的字符串和希望替换成的字符串,然后双击即可运行。 下面为代码,不很复杂,:) 复制代码 代码...
可以替换指定目录及其子目录下所有的快捷方式,自己指定存放快捷方式的路径、要被替换的字符串和希望替换成的字符串,然后双击即可运行。
下面为代码,不很复杂,:)
下面为代码,不很复杂,:)
复制代码 代码如下:
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