Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
To_Efficiency_and_Beyond
454 Views, 1 Reply

Search file path for file

We will have a large project folder structure. I would like to run an ilogic rule that searches for an excel document named "Title Block Information.xlsx". The rule should START searching where the drawing is saved, if file is found return the path, else back up one level and search again, ect. There may be multiple excel sheets in the folder structure but the rule should always find the one saved closest to the drawing.

 

Below you will find what I had when I gave up. The issues:

It searches starting at the top of the file structure and searches down to the drawing. I need it to go the other way.

 

Sub Main
	Dim MyDrawDoc As DrawingDocument=ThisDoc.Document
	Dim mySavePath As String = GetPath(MyDrawDoc)
End Sub

Private Function GetPath(oDrawDoc As DrawingDocument) As String
Try
	Dim sFullDocumentPath As String = IO.Path.GetDirectoryName(oDrawDoc.FullDocumentName)
	Dim aPathParts() As String = Strings.Split(sFullDocumentPath, "\")
	
	For i=0 To UBound(aPathParts)
		sExcelPathx = sExcelPathx & aPathparts(i) & "\"
msgbox(sExcelPathx)
		If System.IO.File.Exists(sExcelPathx & "\Title Block Information.xlsx") Then
			sExcelPathx = sExcelPathx & "Title Block Information.xlsx\"
			bFound = True
		End If
	Next
	
	'only return path if folder $Fabrication Data was found
	If bfound = True Then
		partofpath = Left(sExcelPathx, sExcelPathx.IndexOf(".xlsx"))
		Dim sExcelPath As String = partofpath & ".xlsx"
		'MsgBox(sExcelPath)
		Return sExcelPath
	Else
		Return Nothing
End Try

End Function