Ilogic to search the file, open it and do something

Ilogic to search the file, open it and do something

Anonymous
Not applicable
1,174 Views
6 Replies
Message 1 of 7

Ilogic to search the file, open it and do something

Anonymous
Not applicable

Im looking for a code in vb.net that could search the file (in my case for now .ipt), open it and do something like convert, add parameters etc. Usually the file names comes as  list in excel.

 

This code can search but doesnt do much.

If System.IO.Directory.GetFiles("C:\Inventor Study\", "Test.ipt", IO.SearchOption.AllDirectories).Length > 0 Then
    MsgBox("Found!")
Else
    MsgBox("Not found!")
End If

 This one got error: textbox_sa is not decleared.

Dim allFiles As IEnumerable(Of String) = System.IO.Directory.EnumerateFiles("C:\Inventor Study\", "Test.ipt", IO.SearchOption.AllDirectories)
Dim filePaths As IList(Of String) = allFiles.Where(Function(f) f.IndexOf(TextBox_sa.Text, StringComparison.OrdinalIgnoreCase) <> -1).ToList()

If filePaths.Count = 0 Then
    MessageBox.Show("File not found")
Else
    For Each filePath As String In filePaths
        System.Diagnostics.Process.Start(filePath)
    Next
End If

 Thank you.

0 Likes
Accepted solutions (1)
1,175 Views
6 Replies
Replies (6)
Message 2 of 7

FINET_Laurent
Advisor
Advisor

Where do you want to open the document from ?

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi @FINET_Laurent . I'd like to open it in Inventor.

0 Likes
Message 4 of 7

FINET_Laurent
Advisor
Advisor

From the start menu ? From an assembly file ?

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 7

Anonymous
Not applicable

The code will search the file using ilogic. If found, it should open it in Inventor.

0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Try this 🙂

Dim oFolder As String = "C:\Inventor Study"
Dim oName As String = "Test.ipt"
If System.IO.Directory.Exists(oFolder) = False
	MessageBox.Show("The directory: " & oFolder & " doesn't exist!", "Invalid directory", _
	MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim oFoundDocs As String() = System.IO.Directory.GetFiles(oFolder, oName, IO.SearchOption.AllDirectories)
If oFoundDocs.Length > 0 Then
    For Each oPath As String In oFoundDocs
		ThisApplication.Documents.Open(oPath, True)
	Next
Else
    MessageBox.Show("Couldn't find the document " & oName & " in " & oFolder & " or any of its sub folders!", _
	"No file found", _
	MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

GetFiles returns an array of strings with the filepaths to all the found documents.

Message 7 of 7

Anonymous
Not applicable

It works like magic. A super mega THANK YOU @JhoelForshav .

0 Likes