LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Kosta

Path Constants Relative to the Current VI's Directory Path

Status: New

When I need to access project-related non-LabVIEW files in my VIs, I usually write code like this

File path relative to the VI path in LabVIEW 2019File path relative to the VI path in LabVIEW 2019

I can't afford to use absolute paths because my collaborators don't set up source code control on their computers the same way I have it on mine, and I am fine with that.

 

Writing this type of code is tedious. I have to place four nodes and three wires between them to get one path. On top of that, coming up with the relative path requires either browsing the absolute path, and deletion of the portion of that, or copying and pasting paths from the OS.

 

I would like to express this with a single node. It could be a mode on the path constant, with some visual difference to convey that it's doing something else. Here is one idea

Path relative to the directory that contains the VIPath relative to the directory that contains the VI

You'd be able to browse the path the same way you do today, and change the mode with a right-click and/or configuration dialog.

 

This idea was inspired by TestStand, where you can typically indicate whether you want a path to be stored as absolute or relative.

Kosta
9 Comments
AristosQueue (NI)
NI Employee (retired)

It's a good idea in my opinion. This code snippet is commonly written by many people.

 

Tangent: I am obliged to tell you (because it is in Darren's "you're working too hard in G" presentation) that you don't need the Strip Path. Just change your path to be "..\foo\bar.txt" when you call Build Path. 🙂

 

I do not think this functionality should be a mode on the path constant for the simple reason that such a mode would make the path not be a constant. People use path constants to optimize code, and a path "constant" that doesn't constant fold would be annoying to debug when it came up. Also, I think making it a mode on the path constant would hide its functionality from a lot of people... configuring the path constant just isn't something I think of doing, and it wouldn't show up in palettes or quick drop.

 

I do like the idea of it being its own node. I'd want the "Current VI's Path" glyph worked into the new node so its association is obvious. 

 

Let's call it, for now, the "Current VI Relative Path" node, or CVRP, for the rest of this thread, just so we have a short hand for discussing it.

crossrulz
Knight of NI

1. Paths to non-LabVIEW files should be relative to the Application Directory.  This will point to folder containing either the project (in the IDE) or the executable (in runtime).

 

2. I have a reuse VI that brings in a relative path and it does this all for me.  I think that the best route for NI would be to have a relative path input for those constants.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Kosta
Member

 

 

 

 

 

 

Kosta
cy...
Active Participant

that brings to the question, relative to what? in AQ's response, CVRP will at least point to the folder the VI was residing, what if i want it to be relative to one level up from "current VI" folder? or relative to other folders directly?

 

z:\ one_level_up \ current_VI_folder

z:\ one_level_up \ where_i_want_to \ build_relative_path

 

the path "stripping and building" method can be improved by having a current VI "folder" instead of "path" constant... but I like the ..\ method, is it already available for use?

 

 

CY (expired CLAD)
crossrulz
Knight of NI

cy,

Yes, the ..\ is available and has been available for a very long time.  Related, you can also use .\ to keep the current path.  I know, sounds pointless, but it does have its uses.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Kosta
Member
cy..., I hope my new post answers your questions.
Kosta
cy...
Active Participant

@crossrulz: you mentioned it "." have its uses, can you share?

CY (expired CLAD)
crossrulz
Knight of NI

cy,

I have only used it as the default input for my library VIs I mentioned earlier.  This makes the default output for my Application Directory VI the application directory itself.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
AristosQueue (NI)
NI Employee (retired)

@cy : one of the uses for "." is in serialization so you can record differently "this path" from "no path set" (aka empty path). It's also useful as a sentinel in a long of string parsing to pull out paths. We don't see its utility much in LabVIEW because we rarely work with paths as raw strings.