Jump to content

strip a file path into just the root directory and open it


Recommended Posts

Hi team

I have a task before me and would like to do the following

I have a file path. However, the path has more information in it then needed. In other words, it is drilled down a bit further then i need it to be.

I need to some how strip the first bit of the path and take that information and feed it into the default space for an open file button.

Does anyone have an recommendations on how to complete this task?

Thanks

 

Link to comment

If I understand you correctly, there is a path like "C:\a\b\c" and you need the "\b\c" in order to use it as "D:\default\b\c", right?

Use this to check if one path is relative to another http://zone.ni.com/reference/en-XX/help/371361R-01/glang/compare_two_paths/

It returns the relative part which you can combine with your default path. I don't have access to LV right now, but this should be straightforward.

Link to comment
8 hours ago, Darren said:

I read it the opposite way, he has c:\a\b\c and just needs c:\a or c:\a\b. In those cases, you would use Strip Path.

You are right, that is the standard way to do it, if you know how many elements to remove. You can also utilize the Common Path returned by the compare function depending on what you need.

Edited by LogMAN
Not being rude
  • Like 1
Link to comment
  • 2 weeks later...
On 4/29/2019 at 11:48 AM, ShaunR said:

You can use the Path to Array and then slice out whichever parts of the path you need and concatenate back again.

This is the way i did it.

Seems to work ok

Broke it down into an array and then concat it back together with just the pieces i wanted.

One caveat , when it strips it out, it looses the  ":" colon in C drive, so concat a constant with it.

Thanks for the suggestions. Been a few years since i have worked with LV and getting back into the swing 

 

Link to comment
On 5/8/2019 at 8:15 AM, rscott9399 said:

This is the way i did it.

Seems to work ok

Broke it down into an array and then concat it back together with just the pieces i wanted.

One caveat , when it strips it out, it looses the  ":" colon in C drive, so concat a constant with it.

Thanks for the suggestions. Been a few years since i have worked with LV and getting back into the swing 

 

Is there a reason you're not using the actual "Strip Path" and "Build Path" functions? These allow you to manipulate the path, platform independent. No worries about slash direction and appending the root.

Edited by gleichman
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.