2008-12-05
用jscript脚本批量创建快捷方式
此篇文章为《用batch批量创建快捷方式》的继续讨论,原文章地址为:http://pzy84.blogbus.com/logs/31964835.html
原文摘要:
我找到一个用于创建快捷方式的VBScript脚本:
Source: http://www.experts-exchange.com/Programming/Languages/Scr...
就我目前所知,脚本相比批处理命令有两个好处:
- 可以控制子目录迭代层数,跳过太深的子目录会显著加快进度;
- 可以灵活地使用关键词排除一些文件,从而减少没有使用价值的快捷方式;
// jscript code - NEVER run this script by double-clicking the saved .js file,
// instead, call it within cmd.exe, AND with CScript.
var WshShell = WScript.CreateObject("WScript.Shell");
//-----------------------------------------------------------------------------
var exclusionKeywords = new Array("unins", "setup", "inst", "unwise",
"update", "upgrade",
"conf", "patch", "repair", "升级", "注册", "补丁",
"launch", "game", "load", "run", "start",
"help", "tray", "bugreport",
"vshost", "vmware-");
batch_shortcut("D:\\__launcher", "C:\\Program Files", 2);
batch_shortcut("D:\\__launcher", "D:\\Program Files", 2);
//-----------------------------------------------------------------------------
/*
targetFolder - where are the .exe files?
maxDepth - how deep shoud I dive into subfolder? start from 0.
*/
function batch_shortcut(shortcutFolder, targetFolder, maxDepth)
{
var fso, f, f1, fc;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(targetFolder);
if (maxDepth > 0)
{
fc = new Enumerator(f.SubFolders);
for (;!fc.atEnd(); fc.moveNext())
{
batch_shortcut(shortcutFolder, fc.item().Path, maxDepth - 1);
}
}
fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext())
{
var s = fc.item().Name.toLowerCase(); // lowercase file name
if (s.substr(s.length - 4, 4) == ".exe")
{
var exclude = false;
for (var i = 0; i < exclusionKeywords.length; ++i)
{
if (s.indexOf(exclusionKeywords[i]) != -1)
{
exclude = true;
break
}
}
if (exclude)
continue;
WScript.echo(fc.item().Path);
var shortcutPath = shortcutFolder + "\\" + fc.item().Name.substr(0, s.length - 4) + ".lnk";
var sc = WshShell.CreateShortcut(shortcutPath);
sc.Description = "Shortcut to " + fc.item().Path;
sc.TargetPath = fc.item().Path;
sc.Save();
}
}
}



