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
Solved! Go to Solution.
Solved by MegaJerk. Go to Solution.
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.
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.
Thanks for both replies tried the bottom one first and this worked straight away thank you