From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

how to load files up one step from local working directory

Good afternoon,

 

I have a project assigned to me that has some Ni TestStand code written to read files from a fixed directory and I would like to change this directory to be the directory where the TestStand seqeunce file is located.

 

Furthermore, I would like to be able to step back one directories and forward into a different directory. Is this possible? I know in linux his is done with ..\ preceeding the directory location

 

I want ot do this for variables in TestStand and also for pats in LabView.

 

Cna somebody provide me with the correct syntax, for example if

 

my seq file is C:\User\Test\myseq.seq

 

and I want to open an ini file located in

 

C:\Config\config.ini

 

Should I save the path for the variable as

 

..\..\Config\config.ini ?? 

 

 

Thanks,

-D

0 Kudos
Message 1 of 6
(5,335 Views)

Ideally you would just include that folder in your search directories.  Then you can refer to the file as Config.ini and not have to worry about relativity.

 

However, if this is not an option then you can use the ..\..\ notation to get relativity.  One thing you can do in TestStand is use the API to get the sequence path and then add to that to get a relative path.

 

So in your expression something like this:

 

RunState.SequenceFile.Path + "..\\..\\Config\\Config.ini"

 

The API call will return the absolute path of the sequence file, including the sequence file.

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 6
(5,293 Views)

You might need an extra ..\\ in there.  I wasn't really counting.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 3 of 6
(5,289 Views)

Hi, thank you, 

 

Now do I need the 'RunState.SequenceFile.Path + "..\\..\\Config\\Config.ini" '

or can I just simply use     "..\\..\\Config\\Config.ini" without "RunState.SequenceFile.Path"  and it will use my current directory as a relative path

 

Thanks,

 

0 Kudos
Message 4 of 6
(5,278 Views)

I guess it all depends on where you are using the expression.  Simply putting that into an expression will not give you a relative path.  You need a starting path in order to be relative.  However, there is a good chance it will work in an API call because API calls use your search directories and generally the first item in your Search Directories is the current sequence file folder.   So it just depends on where you are using that string.

 

Regards,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 5 of 6
(5,263 Views)

1) If you want to use a relative path that is resolved the same way as a module path (i.e. using the teststand search directories where looking in the same directory as the sequence file is one of the default possibilities) you can do something like the following:

 

FindFile("..\\Config\\Config.ini", True, Locals.absolutePath)

 

2) RunState.SequenceFile.Path actually includes the sequence file's name, so if you want to build a path from that you would need to do something like the following to parse out the part of the path you care about (though maybe an extra ".." instead of doing this parsing works to get past the file name too, I've never tried that. Perhaps either way is fine.):

 

Locals.absolutePath = Left(RunState.SequenceFile.Path, Find(RunState.SequenceFile.Path, "\\", 0, False, True) + 1) + "..\\Config\\Config.ini"

 

3) Whether or not you need to build an absolute path or can use a relative path depends on what you are doing with the path, if you provide more details on what you are doing with the path we can let you know. In general, you should not use a relative path when calling a win32 API.  See the remarks section of the following where it says, "Multithreaded applications and shared library code should not use the GetCurrentDirectory function and should avoid using relative path names.":

 

http://msdn.microsoft.com/en-us/library/windows/desktop/aa364934%28v=vs.85%29.aspx

 

Though if you are calling a TestStand API then a relative path might be ok, depending on the API call, because some teststand APIs can use the TestStand search directory algorithm to resolve the path (basically the equivalent of 1 above).

 

Hope this helps,

-Doug

Message 6 of 6
(5,210 Views)