Skip to main content

Command to automatically override existing databases/files

Hello everyone!
When preparing an IDEA script, is there any command I can use that will tell IDEA to automatically override any existing database in the project and/or existing files the script might create?
I have scripted more with ACL and in ACL, that command is SET SAFETY OFF.  When this command is used in a script, any existing ACL table or file that is created by the script will be automatically overridden.
I was checking to see if IDEA had a similar command.
Thanks in advance for the help!
Mike

Brian Element Mon, 06/20/2016 - 13:44

Hi Mike,

Sorry for not getting back to you sooner.  The command you are looking for is:

IgnoreWarning(True)

Just add this at the beginning of the script and you won't get any pop-ups asking you to overwrite files that already exists.

Brian

JHDCC Thu, 06/06/2019 - 05:05

Hi all,
I have used IgnoreWarning(True) in a script, which successfully overwrites the existing databases, but does not overwrite exported files.
Should exports be overwritten when using IgnoreWarning(True)?
If not, is there any other way to accomplish this?

Brian Element Thu, 06/06/2019 - 14:53

Hi JHDCC, when they were putting the scripting language together they decided not to add that function, the reason for that is probably lost in time.

What you can do is first check if the file exists and if it does delete it manually before doing the save.  Here is some code for you to do it.


Sub Main
	Call deleteFileIfExists("C:\Users\User\Documents\My IDEA Documents\file to delete.xls")
End Sub

Function deleteFileIfExists(sFilename As String)
	Dim fso    
	Set fso = CreateObject("Scripting.FileSystemObject")
	
	If (fso.FileExists(sFilename)) Then
		fso.DeleteFile sFilename
	End If
End Function

JHDCC Thu, 06/13/2019 - 09:24

Thanks Brian
For the benefit of anyone else picking this up, rename the path in this line with the file you want to delete and include this in the top of the macro between the Sub Main and End Sub lines. Include a seperate line for each file which is to be deleted.
<code> 
Call deleteFileIfExists("C:\Users\User\Documents\My IDEA Documents\file to delete.xls")
</code> 
Include the below in the body of the macro. This does not need altering and only needs including once it seems - I presume the file path in the top section is inserted into the  function and it runs for  each instance.
<code> 
FunctiondeleteFileIfExists(sFilename As String)DimfsoSetfso = CreateObject("Scripting.FileSystemObject")If(fso.FileExists(sFilename))Thenfso.DeleteFilesFilenameEndIfEndFunction
</code> 

The website encountered an unexpected error. Try again later.