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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic File Path

Solved!
Go to solution

Hi ALL,

 

I am playing a wave file using play sound file vi. I have made the file a constant.

It runs fine. But I fear that if I give my vi and wave file to someone else to run, there may be

problems as the sound file path may not be the same as on my PC. Can I make

the path 'dynamic'?

 

Thanks.

Message 1 of 8
(5,693 Views)

Just make a right click on the path constant and choose "Change to control". This wil create a control on the Front Panel with the value of the constant as default.

You just need to position the control on the Front Panel to give it a nice look.

Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 2 of 8
(5,683 Views)

Another way to take care of this issue would be to put the file in a location that you know where it is. You could put it in the data folder when you make the exe and then get the vi path from the owing vi and generate the path that way.

 

Example:

Owining VI is in C:\program files\programx\programx.exe

 

You could get the path to the owing vi:

C:\program files\programx\ then add the data file path to get:

C:\program files\programx\\data\soundfile.wav

Tim
GHSP
Message 3 of 8
(5,671 Views)

Hi Waldemar,

 

Thanks for your reply.

 

I did try however when I copied the folder containing the vi and wave file to

other location, the path is still showing at the old location and when I run

it gives me an error like couldn't find file.

 

Any other way?

 

Rgds.

0 Kudos
Message 4 of 8
(5,669 Views)

Hi aestet,

 

Thanks for your reply.

 

I do know where the file is on my PC. The problem is when I give it to a customer for example,

I wouldn't know where he will place the file. Most likely it will not be the same path as my PC.

Of course unless I tell him to make the necessary folders or he has to select the path from his

PC. This is what I would like to avoid.

 

Is it possible for someone else to run the program on his PC and the sounds will play without having to

do this and that...?

 

Rgds. 

Message 5 of 8
(5,660 Views)

The

 

File I/O >>> File Constants >>> Current VI's Path

 

will return the path to the VI on who's block diagram it resides.

 

In the development environment you can use the

 

File I/O >>> Stip Path

 

to get the folder spec of where that VI is located on disk. You can then use that folder spec along with

 

File I/O >>> Build Path

 

to develop you file spec.

 

Please note that in an exe you may have to use the "Strip Path" more than once to get a folder spec because the VIs in a exe are located inside the exe.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 8
(5,654 Views)
I am reiterating what has already been said, but what you want to do is have the sound file's location relative to the exe be a constant. To use aeastet's example, the sound files can be located in a directory with a fixed relative path with respect to the exe (or vi). Then, as Ben described, you just build the path to the sound file programmatically starting with the "Current VI's Path" constant from the File Constant's palette. Ben is correct, you will have to strip the path twice if you run it from within an exe (just think of an exe as a folder with all your vi's in it).
Message 7 of 8
(5,646 Views)
Solution
Accepted by topic author OSMAN

The OpenG toolkit has a function called Current VI's Parent Directory, which returns the folder where the VI is stored, you can use relative paths to build your path.

 

This is a proven working solution.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 8 of 8
(5,636 Views)