Skip navigation

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


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, oArgs
Set oArgs = WScript.Arguments
FQFN = oArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheParent = fso.GetParentFolderName(FQFN)
Wscript.Echo GetTheParent



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish