LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

save file with fixed file extension

Solved!
Go to solution

Hello,

in my programme the user should put in the name of a file which will be saved. The file extension name should be automatically added to

the file name, example:

the user put in "Log0001" and the complete file name is "log0001.csv"

 

I tried the following function:

 

abue_0-1647718575660.png

for type I used  a constant with ".csv", but this doesn't work, the error message was: "Set file and program type in Param-nethos.vi<APPEND>
Logg0001"

 

Is this the right function for my requirement or are there other possibilities?

0 Kudos
Message 1 of 10
(1,870 Views)

Just use Concatenate String to add ".csv" to the file name and then build the path as you do now.  Then you can create/replace/open the file.


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
0 Kudos
Message 2 of 10
(1,834 Views)

Hello crossrulz,

thank you for your replay.

But how could I adding the extension using the base path control?

I tried the 'Build Path' function, but this doesn't work:

abue_0-1648223514392.png

 

0 Kudos
Message 3 of 10
(1,798 Views)

Try something like this:

FnCapture.PNG

 

Also note that this does not check for illegal characters in the path or name

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 10
(1,783 Views)

Build Path adds another layer to your path. The file path you would get out of that would be something like:

..\some_base_path\.txt

 

Convert the path to a string, and use the Concatenate Strings function to add the .csv to the end of the file name. Alternatively, you could use the File Dialog express VI to put up a dialog for the user. Using that, you can specify a default file type. Depends on your use case.

Wes Pierce
Principal Engineer
Pierce Controls
0 Kudos
Message 5 of 10
(1,779 Views)

Hi Wes,

 


@Wes_P wrote:

Convert the path to a string, and use the Concatenate Strings function to add the .csv to the end of the file name.


No!

Don't convert the whole path to a string just to manipulate a filename! That's where StripPath/BuildPath come into play!

 

(Converting a full path to string may/will fail once you run the code on a different target, like changing from Windows to MacOS or LinuxRT!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(1,764 Views)

Great point. And I completely agree - the benefits of using the path file type and associated functions for cross platform (or even cross-locale within windows) are super important. I was responding the the above comment in mind - using Concatenate Strings. That function won't work on paths, hence the conversion. But 100%, only convert the piece of the path you need, using strip and build path.

 

I suspect though that the file name comes into the application as a string from user input, so in that case the extension should be added before a full path is ever created.

Wes Pierce
Principal Engineer
Pierce Controls
0 Kudos
Message 7 of 10
(1,757 Views)
Solution
Accepted by topic author abue

I think he meant, don't convert the whole string to a path. Using Strip Path returns just the filename as a string. Example:

path.png

 

And if you want to be extra safe, use "Get file extension" instead of "Strip path":

path2.png

 

This method will take "C:\MyTest.txt" and turn it into "C:\MyTest.csv". The "strip path" method would return "C:\MyTetst.txt.csv".

0 Kudos
Message 8 of 10
(1,748 Views)

I am working on Win7 using LabVIEW18. But hopefully this can help you.

I simply use a build path function. Wire your path into the upper terminal. On the front panel place a string control(this is where your user will input their file name). On your block diagram use a concatenate string to append the file name and extension together. Wire those into your build path. You can double check the outcome using an indicator before moving forward. Then I use the open file function, with a constant of your choosing(whatever is needed in your situation), for the example below I used Create/Replace. I wrote to the file and then closed the file, saving it to the path name created earlier. 

I hope this helps.

Creig Mills
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 9 of 10
(1,734 Views)

thank you very much for your support, i decided to use BertMcMahan's last solution.

This is perfect for me.

0 Kudos
Message 10 of 10
(1,717 Views)