AnsweredAssumed Answered

Taking the last folder out of a file path

Question asked by Robert Conklin on Mar 13, 2020
Latest reply on Mar 13, 2020 by Robert Conklin

Or stripping off the last sub directory in a path. I have a nice macro that will save a SLDDRW as a “DWG”

It currently saves the “DWG” in, and makes one if it does not exist, an AutoCad directory IN THE CURRENT folder.

I just want to change it to save the “DWG” in, and makes one if it does not exist, an AutoCad directory IN THE FOLDER ABOVE THE CURRENT folder.

The code to get the current path now is thus:

 

filename = swModel.GetPathName

currPath = Left(filename, InStrRev(filename, "\"))

filename = Right(swModel.GetPathName, Len(swModel.GetPathName) - InStrRev(swModel.GetPathName, "\"))

AutoCadPath = currPath & "AutoCad"

 

I just do not know how to return a path “Up-One” level\directory

uponedir=?????

 

_____EDIT_____EDIT_____EDIT______________________________

Following the pointers by David Lane and adding the following bits where needed...

Dim oFSO                As Object
Dim CurPthFilNm         As String
Dim uponedir            As String
-----------------------------------------------------------------

Set oFSO = CreateObject("Scripting.FileSystemObject")

CurPthFilNm = swModel.GetPathName

uponedir = oFSO.GetFile(CurPthFilNm).ParentFolder.ParentFolder.Path & "\"

AutoCadPath = uponedir & "AutoCad"

It works great

Thanks

Outcomes