Find Folder using Ilogic

Find Folder using Ilogic

Andrew_Burnett
Enthusiast Enthusiast
1,723 Views
4 Replies
Message 1 of 5

Find Folder using Ilogic

Andrew_Burnett
Enthusiast
Enthusiast

Looking for some help with some code to find a job folder on our network using Ilogic or VBA code.  We use a folder structure that contains the job number and a description of the job.  The description varies by job.  The folder has the job number - description (Example: 123456 is the job number.  The folder name is 123456 - pipe parts)  In the Inventor file the user enters the job number.  I want to use the job number the user entered to find the correct job folder and use it as the save location in my Ilogic rule.  I have tried a couple codes but none will find the folder.  Any help would be greatly appreciated.

 

0 Likes
Accepted solutions (2)
1,724 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

is this what you are looking for?

Dim mainPath As String = "c:\temp\"
Dim mainDirectory As IO.DirectoryInfo = New IO.DirectoryInfo(mainPath)

Dim jobNumber = InputBox("Enter the job number", "Jon number", "")

Dim jobDirectoryName As String = ""
For Each jobDirectory As IO.DirectoryInfo In mainDirectory.GetDirectories()
	If (jobDirectory.Name.StartsWith(jobNumber)) Then
		jobDirectoryName = jobDirectory.FullName
	End If
Next

If (String.IsNullOrEmpty(jobDirectoryName)) Then
	MsgBox("Directory with jobnumber " + jobNumber + " not found!")
End If

MsgBox(jobDirectoryName)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

Andrew_Burnett
Enthusiast
Enthusiast

Exactly what I was looking for.  Thank you for the help.  It is greatly appreciated.

0 Likes
Message 4 of 5

Andrew_Burnett
Enthusiast
Enthusiast

I found another issue with how we structure stuff.  We also use the vault for storing files.   The question I have is the structure of the vault contains the customer name and then the job number.  example structure:  C:\Work\Jobs\Customer name\Job Number.  Is there a way for me to search through all of the customer folders to find the job number folder that matches what the user has entered?  Any help would be greatly appreciated.  The last code worked great for finding it on the network.

 

Thank you

0 Likes
Message 5 of 5

Andrew_Burnett
Enthusiast
Enthusiast
Accepted solution

I figured it out.  needed to sort down through the directories.  Here is the code I came up with.

 

Dim mainPath As String = "c:\Work\Jobs\"
Dim mainDirectory As IO.DirectoryInfo = New IO.DirectoryInfo(mainPath)

Dim jobNumber = InputBox("Enter the job number", "Job number", "")

Dim jobDirectoryName As String = ""

For Each jobDirectory As IO.DirectoryInfo In mainDirectory.GetDirectories()
	For Each jobDirectory2 As IO.DirectoryInfo In jobDirectory.GetDirectories()
		If (jobDirectory2.Name.StartsWith(jobNumber)) Then
		jobDirectoryName = jobDirectory2.FullName
	End If
Next
Next


If (String.IsNullOrEmpty(jobDirectoryName)) Then
	MsgBox("Directory with jobnumber " + jobNumber + " not found!")
End If

MsgBox(jobDirectoryName)
0 Likes