Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic File Check Before Save

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Dhall_1803
5359 Views, 3 Replies

Ilogic File Check Before Save

I am looking to do a file check prior to save i.e

 

If file.exists("File name and Location") Then

 MessageBox.Show("Already Exists")

Else

ThisDoc.Document.SaveAs("File name and Location")

End If

 

This doesn't work in Inventor unfortunately, can anyone suggest a fix

 

Thanks

3 REPLIES 3
Message 2 of 4
mrattray
in reply to: Dhall_1803

I have this snippet for VBA. It should work for iLogic, too.

 

Function FileExists(ByVal path As String, Optional bFindFolders As Boolean) As Boolean
    'Purpose:   Return True if the file exists, even if it is hidden.
    'Arguments: strFile: File name to look for. Current directory searched if no path included.
    '           bFindFolders. If strFile is a folder, FileExists() returns False unless this argument is True.
    'Note:      Does not look inside subdirectories for the file.
    'Author:    Allen Browne. http://allenbrowne.com June, 2006.
    Dim lngAttributes As Long

    'Include read-only files, hidden files, system files.
    lngAttributes = (vbReadOnly Or vbHidden Or vbSystem)

    If bFindFolders Then
        lngAttributes = (lngAttributes Or vbDirectory) 'Include folders as well.
    Else
        'Strip any trailing slash, so Dir does not look inside the folder.
        Do While Right$(path, 1) = "\"
            path = Left$(path, Len(path) - 1)
        Loop
    End If

    'If Dir() returns something, the file exists.
    On Error Resume Next
    FileExists = (Len(Dir(path, lngAttributes)) > 0)
    'MsgBox (FileExists)
End Function

 

You can also search for and ask questions about programming in Inventor here: Inventor Customization.

Mike (not Matt) Rattray

Message 3 of 4
MegaJerk
in reply to: Dhall_1803

Actually, you can! You just need to access the System.IO namespace in order to do so. Consider the following code:

 

If System.IO.File.Exists("File_Path_Here") Then
MessageBox.Show("The file exists!")
Else
'''Coooooode
End If

 

 

You could also save yourself some keystrokes and simply Import the namespace from the get-go, which is helpful if you find that you’ll be using it regularly:

Imports System.IO

If File.Exists("File_Path_Here") Then
	MessageBox.Show("The file exists!")
	Else 
	'''Coooooode
End If  

 


For more System.IO.File methods, please see : this page

 

I hope that this helps to solve your problem. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 4 of 4
Dhall_1803
in reply to: MegaJerk

Thanks for both replies tried the bottom one first and this worked straight away thank you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report