How to Retrieve Parent Directory for Files and Folders
The following code will return the parent directory of a given directory , or the directory of a given filename.
Dim str as String
Dim i as Integer
str = “C:\Files\test\baby.jpg”
i = InStrRev(str, “\”)
str = Left(str, i)
MsgBox str
The output for the above code will be “C:\Files\test\”
If the input is a directory (F:\Program Files\MSN) it will return that directory’s parent (F:\Program Files\).
If the input is a file (F:\changes\MAR1\test.txt) it will return that file’s directory (F:\changes\MAR1\).
