JSI Tip 10291. How can a Vbscript determine a files parent folder?

Jerold Schulman

March 20, 2006

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


When writing a batch script, you can determine the parent folder of a file parameter by parsing the parameter. If %1 is a fully qualified file name, then set GetTheParent=%~DP1 would define the parent folder.

Using Vbscript, you could:

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



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