If you wanted to set the current directory to the parent folder of a fully qualified file name:
Dim fso, oArgs Set oArgs = WScript.Arguments FQFN = oArgs(0) Set fso = CreateObject("Scripting.FileSystemObject") GetTheParent = fso.GetParentFolderName(FQFN) oShell.currentdirectory = GetTheParent
Sample
cscript //nologo c:\util\test2.vbs %Systemroot%\SYSTEM32\DRIVERS\tcpip.sys returns: C:\WINDOWS\SYSTEM32\DRIVERS C:C:\WINDOWS\SYSTEM32\DRIVERS where test2.vbs contains: Dim fso, oArgs Set oArgs = WScript.Arguments FQFN = oArgs(0) Set fso = CreateObject("Scripting.FileSystemObject") GetTheParent = fso.GetParentFolderName(FQFN) Wscript.Echo GetTheParent set oShell = createobject("wscript.shell") wscript.echo oShell.currentdirectory oShell.currentdirectory = GetTheParent wscript.echo oShell.currentdirectory
0 comments
Hide comments