Skip to main content

Move File name .IMD

Hi,
Is it possible using script to move file name .IMD from local project to another folder,
Thank you.

Brian Element Wed, 04/04/2018 - 07:28

Hi Ahmed, here is some example code that allows you to pick and file and then pick a folder and then it moves the file to the new folder.  I have also attached the script.

 


Option Explicit

Dim sFilename As String
Dim sDestinationPath As String

Sub Main

	Call getFileToMove()
	Call getFolderToMoveTo()
	Call moveFile()

End Sub

Function moveFile()
	Dim pm As Object
	
	' Run task on the current Desktop project.
	Client.RunAtServer False
	
	' Access the project management object.
	Set pm = Client.ProjectManagement
	
		' Move a file from the current Desktop project to another local directory.
		
		pm.MoveDatabase sFilename, sDestinationPath
		' Refresh the File Explorer.
		
		Client.RefreshFileExplorer
		
		' Clear the path.
	
	Set pm = Nothing
End Function

Function getFolderToMoveTo()
	Dim BrowseFolder As String
	Dim oFolder As Object
	Dim oFolderItem As Object
	Dim oPath As String
	Dim oShell As Object
	Dim strPath As String
	
	Set oShell = CreateObject( "Shell.Application" )
	Set oFolder = oShell.Namespace(17) 'the 17 indicates that we are looking at the virtual folder that contains everything on the local computer
	Set oFolderItem = oFolder.Self
	strPath = oFolderItem.Path
	Set oFolder = oShell.BrowseForFolder(0, "Please select the folder where the files are located:", 1, strPath)
	If (Not oFolder is Nothing) Then
		Set oFolderItem = oFolder.Self
			oPath = oFolderItem.Path
			
			If Right(oPath, 1) <> "\" Then
				oPath = oPath & "\"
			End If
	
	End If
	
	sDestinationPath = oPath
End Function

Function getFileToMove()
	Dim obj As Object
	Set obj = client.CommonDialogs
		sFilename = obj.FileExplorer()
	Set obj = Nothing
End Function


Ahmed Thu, 04/05/2018 - 05:55

Thank you very much Brian it works perfectly. However, if I want to use this script without displaying the dialog box, ie I write directly the name of the file to move as well as its path where should I make the changes? because this action to move the file effect another script that is waiting to run.
 

Brian Element Fri, 04/06/2018 - 07:12

In reply to by Ahmed

Hi Ahmed, then all you need is the move function and you can change the following line:

pm.MoveDatabase sFilename, sDestinationPath

Could be:

Set pm = Client.ProjectManagement

pm.MoveDatabase "c:\Documents\user name\My IDEA Documents\IDEA Projects\My IDEA Project\Sample-Customers.IMD", "c:\new path"

Set pm = Nothing

Most of the code was getting the location of the files but if you know that all you need is the three lines above to move a file, the first part is the location of the file you want to move and the second part is the path of where you want to move it to.

Brian

Ahmed Tue, 04/10/2018 - 03:05

Hi Brian,
Thank you very much for this solution .
It works as I expected and I'm sorry for my late answer to your message.

mkamagate Mon, 03/18/2019 - 14:22

Greetings,
I am new to the IDEA scripting world. Is there a script to select IMD file from a specific folder for testing? i am currently running testing on several statements in iDEA and would like to select them individually for testing. additionally is there a way to change the name of the IDEA result database?
Thank you for your assistance.

Brian Element Tue, 03/19/2019 - 07:33

In reply to by mkamagate

Hello and welcome to the site.

For your second question usually there is a function that allows you to change the default result name, an example is the stratification, if you looks in the Language Browser under Stratification you will see the following line:

task.ResultName = "Stratification"

Just change the stratification to the name you wish.  You can check the Language Browser for other tests.

For your first question I don't quite understand, you can hard code the names of the IMD files in your script for testing, maybe give an example of what you are trying to do.

Thanks

Brian

mkamagate Tue, 03/19/2019 - 10:28

I was trying to run the following script and kept geting the error on line 101 databsase exist or is in use. I just wanted to be able to select a database and conduct a direect extraction based on charges greater than 0.00.
Regards,

Brian Element Wed, 03/20/2019 - 08:25

In reply to by mkamagate

The main reason is that your script hasn't referenced a file yet, as soon as you click a button it runs as it is not currently running the DisplayIt function.  If you click on the dlgMenu and make sure you have selected the entire dialog you should see something in the Properties called Function that is currently set as NewDialog1, changeit to DisplayIt and now the dialog will call the DisplayIt function which will allow you to select your file.