var objShell = WScript.CreateObject("WScript.Shell");
WScript.Echo("起動時のカレントディレクトリ表示:\r\n"+objShell.CurrentDirectory);
// カレントディレクトリ変更
objShell.CurrentDirectory = "C:\work";
WScript.Echo("変更後のカレントディレクトリ表示:\r\n"+objShell.CurrentDirectory);
WScript.Echo("スクリプトの絶対パスを表示:\r\n"+WScript.ScriptFullName);
var fs = WScript.CreateObject("Scripting.FileSystemObject");
var fi = fs.GetFile(WScript.ScriptFullName);
WScript.Echo("スクリプトのあるディレクトリのパスを表示:\r\n"+fi.ParentFolder.Path);
// カレントディレクトリをスクリプトのあるディレクトリへ変更
objShell.CurrentDirectory = fi.ParentFolder.Path;
WScript.Echo("変更後のカレントディレクトリ表示:\r\n"+objShell.CurrentDirectory);
■実行結果
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
起動時のカレントディレクトリ表示:
C:\
変更後のカレントディレクトリ表示:
C:\work
スクリプトの絶対パスを表示:
C:\WSH\RunSSCS.js
スクリプトのあるディレクトリのパスを表示:
C:\WSH
変更後のカレントディレクトリ表示:
C:\WSH
最終更新:2009年06月24日 14:27