JSI Tip 10292. How can a Vbscript set the current folder to a files parent folder?

Jerold Schulman

March 20, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today


If you wanted to set the current directory to the parent folder of a fully qualified file name:

Dim fso, oArgsSet oArgs = WScript.ArgumentsFQFN = oArgs(0)Set fso = CreateObject("Scripting.FileSystemObject")GetTheParent = fso.GetParentFolderName(FQFN)oShell.currentdirectory = GetTheParent

Sample

cscript //nologo c:utiltest2.vbs %Systemroot%SYSTEM32DRIVERStcpip.sysreturns:C:WINDOWSSYSTEM32DRIVERSC:C:WINDOWSSYSTEM32DRIVERSwhere test2.vbs contains:Dim fso, oArgsSet oArgs = WScript.ArgumentsFQFN = oArgs(0)Set fso = CreateObject("Scripting.FileSystemObject")GetTheParent = fso.GetParentFolderName(FQFN)Wscript.Echo GetTheParentset oShell = createobject("wscript.shell")wscript.echo oShell.currentdirectoryoShell.currentdirectory = GetTheParentwscript.echo oShell.currentdirectory



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like