03-19-2022 02:44 PM
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:
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?
Solved! Go to Solution.
03-20-2022 02:51 PM
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.
03-25-2022 10:53 AM
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:
03-25-2022 11:25 AM - edited 03-25-2022 11:26 AM
Try something like this:
Also note that this does not check for illegal characters in the path or name
03-25-2022 11:28 AM
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.
03-25-2022 11:55 AM
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!)
03-25-2022 12:25 PM
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.
03-25-2022 12:51 PM
I think he meant, don't convert the whole string to a path. Using Strip Path returns just the filename as a string. Example:
And if you want to be extra safe, use "Get file extension" instead of "Strip path":
This method will take "C:\MyTest.txt" and turn it into "C:\MyTest.csv". The "strip path" method would return "C:\MyTetst.txt.csv".
03-25-2022 03:08 PM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-27-2022 08:44 AM
thank you very much for your support, i decided to use BertMcMahan's last solution.
This is perfect for me.