Skip to main content

Changing working directory down one level

Hi again,
I'm having an issue with Client.WorkingDirectory
I'm running a script that places files into a folder "Audit Data".
As part of this script it opens one of these files, places a URL into a field, creates this as an action field, and then looks to another macro to invoke I Explorer
If I put the full path of the second macro into the script it works a dream. However, the macro will be used by different people and so the path will change.
I can't use the working directory as the macros.ilb folder is back one level i.e. my working directory is IDEA\Audit Data.ilb and the macros are in IDEA\macros.ilb
I know that ChDir".." will allow me to move up one level
However, I can't figure out how to move down one level
Any help would be greatly appreciated.
thanks again,
Phil
 
 

Brian Element Thu, 06/08/2017 - 13:16

Hi Phil,

Just to make sure I understand this.  So in the action field that you create it is referencing a script to open up the URL and because of the locations of the files you are having a hard time mapping the location of the script.

So my question is would the location of the script always stay relative to your folder.  So would it always have the following structure:

IDEA\Audit Data.ILB

IDEA\macros.ILB

So the file would be created and stored in IDEA\Audit Data.ILB but the macro it needs to reference would be IDEA\macros.ILB, would Audit Data.ILB and macros.ILB always be the same folders?

Let me know and I should be able to help you out.

Brian

pcallan0 Fri, 06/09/2017 - 05:20

Hi Brian,
That's exactly it.
The script creates a folder "audit data", import files and moves them into the folder, and then does a series of summarizations, extractions etc.
So the working folder will always be IDEA\Audit Data.ILB and the macro folder will always be IDEA\macros.ILB
Thanks,
Phil
 

Brian Element Fri, 06/09/2017 - 17:09

Hi Phil, here is some code for you.  The script first gets the full project folder path and then removes the project folder.  It then adds the Macrol.ILB info to the folder info along with the script name and finally adds this info to the action field.  Let me know if you have any questions.

Brian


Option Explicit
 
Dim sWorkingDirectory As String
Dim sProjectFolder As String
Dim sMacroFolder As String
 
Sub Main
	'get the working directory for the current project
	sWorkingDirectory = Client.WorkingDirectory()
	'get the project folder (1 step above the project)
	sProjectFolder = getProjectFolder(sWorkingDirectory )
	'add the folder name to the Project folder
	sMacroFolder = sProjectFolder & "Macro.ILB\"
	'add the actoin field
	Call addActionField()
End Sub
 
'get the project folder portion from the working folder
Function getProjectFolder(sFolder As String) As String
	Dim sReverseFolder As String
	Dim iFirstSlash As Integer
	
	'Reverse the folder order
	sReverseFolder = iReverse(sFolder)
	'Get rid of the first back slash that is located as the first character (last character before doing reverse)
	sReverseFolder = Mid(sReverseFolder, 2, Len(sReverseFolder)) 
	'Find the location of the first slash (last back slash prior to reversing the folder info)
	iFirstSlash = InStr(1, sReverseFolder, "\")
	
	'extract the Project Folder portion and return it.
	getProjectFolder = Mid(sFolder, 1, Len(sFolder) - iFirstSlash)
End Function
 
Function addActionField()
        Const AF_FIELD = 2
        Const AF_RecordNumber = 0
        Const AF_UserDefinedText = 1
        
        Dim db As database
        Dim table As table
        Dim field As field
        
        Dim sScriptLocation As String
        'set-up a variable to hold the script location
        sScriptLocation = sMacroFolder & "ie.iss"
        
        'example using Sample-Bank Transactions.IMD from samples folder, a Link field was previously created.
        Set db=Client.OpenDatabase("Sample-Bank Transactions.IMD")
                Set table = db.TableDef
                        Set field = table.GetField("LINK")
                                
                                field.SetActionFieldForIDEAScript sScriptLocation, AF_FIELD,  "LINK", AF_UserDefinedText,  "", AF_UserDefinedText,  "", AF_UserDefinedText,  ""
                        
                        Set field = Nothing
                Set table = Nothing 
        Set db = Nothing
End Function

pcallan0 Wed, 07/05/2017 - 10:17

Hi Brian,
My apologies, I thought I had responded to your last message.
the script worked for me.
Thanks a million,
 
Phil