::Hikaru's blog

調べたこと, 考えたことをメモ.
<< August 2017 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 >>

スポンサーサイト

一定期間更新がないため広告を表示しています

- | permalink | - | -

ファイル選択ダイアログ

// ファイル選択ダイアログ var dialog = new ActiveXObject("UserAccounts.CommonDialog") dialog.Filter = "All Files (*.*)|*.*" dialog.ShowOpen(); // フォルダ選択ダイアログ var app = new ActiveXObject("Shell.Application"); app.BrowseForFolder(0, "", 0);
WSH, JScript | permalink | comments(0) | trackbacks(0)

renameFile

function renameFile(path, name) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var file = fso.GetFile(path); file.Name = name; }
WSH, JScript | permalink | comments(0) | trackbacks(0)

sendToRecycleBin

function sendToRecycleBin(path) { var app = new ActiveXObject("Shell.Application") var recycle_bin_folder = app.Namespace(10); recycle_bin_folder.MoveHere(path); WScript.Sleep(200); }
WSH, JScript | permalink | comments(0) | trackbacks(0)

quote, unquote

function quote(str) { return str.charAt(0) == '"' && str.charAt(str.length - 1) == '"' ? str : '"' + str + '"'; } function unquote(str) { return str.charAt(0) == '"' && str.charAt(str.length - 1) == '"' ? str.substring(1, str.length - 1) : str; }
WSH, JScript | permalink | comments(0) | trackbacks(0)

confirm, prompt

function confirm(text) { var code = 'Function fn(text, buttons, title)¥n' + 'fn = MsgBox(text, buttons, title)¥nEnd Function'; var sc = new ActiveXObject("ScriptControl"); sc.Language = "VBScript"; sc.AddCode(code); return sc.Run("fn", text, 4 | 32, "") == 6; } function prompt(text, defaultText) { var code = 'Function fn(text, title, defaultText)¥n' + 'fn = InputBox(text, title, defaultText)¥nEnd Function'; var sc = new ActiveXObject("ScriptControl"); sc.Language = "VBScript"; sc.AddCode(code); return sc.Run("fn", text, "", defaultText); } // 追記 - confirmはWshShell.Popupを使う方法もある function confirm(text) { var shell = new ActiveXObject("WScript.Shell"); return shell.Popup(text, -1, "", 4 | 32) == 6; }
WSH, JScript | permalink | comments(0) | trackbacks(0)

redirect

function redirect(command, outputFilename) { var exec = shell.Exec(command); var outputFile = fso.CreateTextFile(outputFilename, true); while (!exec.StdOut.AtEndOfStream) { outputFile.WriteLine(exec.StdOut.ReadLine()); } outputFile.Close(); }
WSH, JScript | permalink | comments(0) | trackbacks(0)