I'm looking to do a recusrive search of a file in a folder using iLogic, but I need to access Filesystemobject
how do I access these in iLogic?
Dim FSO AsNew FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Many thanks in advance,
Dave
Solved! Go to Solution.
Solved by rjay75. Go to Solution.
Not sure of how to through iLogic....
But here's some VBA stuff to get you on the right track...Folder Dialog
Dim pathSelected As String 'Allows the user to select a folder Dim ShellApp As Object Set ShellApp = CreateObject("Shell.Application"). _ BrowseforFolder(0, "Choose Folder", 0, OpenAt) pathSelected = ShellApp.self.path Me.TextBox1.Text = pathSelected Set ShellApp = Nothing
OpenFileDialog:
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long Public Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Public Function SelectFileOpenDialog() Dim strTemp, strTemp1, pathStr As String Dim i, n, j As Long Dim OpenFile As OPENFILENAME Dim lReturn As Long Dim sFilter As String Dim Fname As String OpenFile.lStructSize = Len(OpenFile) sFilter = "Assembly Files (*.iam)" & Chr(0) & "*.IAM" & Chr(0) OpenFile.lpstrFilter = sFilter OpenFile.nFilterIndex = 1 OpenFile.lpstrFile = String(257, 0) OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1 OpenFile.lpstrFileTitle = OpenFile.lpstrFile OpenFile.nMaxFileTitle = OpenFile.nMaxFile OpenFile.lpstrInitialDir = dir_path OpenFile.lpstrTitle = "Select An Assembly" OpenFile.flags = 0 lReturn = GetOpenFileName(OpenFile) If lReturn = 0 Then MsgBox "No file selected. Please try again." Else Fname = Trim$(OpenFile.lpstrFile) ' Copies the filename to "Fname" n = FileLen(OpenFile.lpstrFile) 'Length of the file Resolve_and_Open.FileName.Text = Fname End If End Function
A code I use, using filesystemobject, to copy contents of a folder to another folder...
Option Explicit Sub Folder_Testing() Dim path As String If Dir("C:\\InventorTempFolder\\\", vbDirectory) = "" Then 'Creates a new temporary directory path for a folder copy MkDir "C:\\InventorTempFolder\\\" SetAttr "C:\InventorTempFolder", vbNormal Else: MsgBox "Please delete the C:\InventorTempFolder and restart program." End If Dim FSO As Object Dim FromPath As String Dim ToPath As String FromPath = Browser.TextBox1.Text ToPath = "C:\\InventorTempFolder\\\" If Right(FromPath, 1) = "\" Then FromPath = Left(FromPath, Len(FromPath) - 1) End If If Right(ToPath, 1) = "\" Then ToPath = Left(ToPath, Len(ToPath) - 1) End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " does not exist. Please restart process." Exit Sub End If FSO.CopyFolder Source:=FromPath, Destination:=ToPath 'Copies the folder and all its files in to the new temporary directory path End Sub
A code I use, using filesystemobject, to delete a directory:
Option Explicit ' Delete this directory and all the files it contains. Sub DeletetheDirectory() Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") FSO.deletefolder "C:\\InventorTempFolder" On Error Resume Next End Sub
Hope this gets you on the right track!
Many thanks Ali, for the verbose answer.
However, what I need to be able to do is access the Filesystemobject in iLogic.
I assume a library needs to be loaded, but I don't know how to di this.
Perhaps someone out there does....
Dave
In iLogic you can to get to the FileSystemObject it's ThisApplication.FileManager.FileSystemObject. However you also have access to the .NET System.IO class.
Imports SysIO = System.IO
I use this syntax to map it to SysIO, because some parts of it can clash with the inventor api. I use it like so, SysIO.File.Exists("afile").
Can't find what you're looking for? Ask the community or share your knowledge.