LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Get name of a file

I have a full filename information (directory + file extension) and I would like to have only the filename without directory without extension. Is is possible with LabWindows

 

For instance,

 

I have c:\test\text1.txt and I would have text1

 

Thanks 

0 Kudos
Message 1 of 8
(5,160 Views)
Yes, it's possible. You can use the function SplitPath from the utility library.
0 Kudos
Message 2 of 8
(5,159 Views)

....edit time has expired, Smiley Sad

 

Yes, it's possible. You can use the function SplitPath from the utility library. This will give you the file name. In the next step, you can use FindPattern ( path_name, 0, -1, ".", 0, 1 ) to search for the dot., and using CopyString for copying the last few characters; the number of characters you need to copy is returned from FindPattern.

0 Kudos
Message 3 of 8
(5,149 Views)

To exclude the extension you can do the following:

if ((nc = FindPattern (FileName, 0, -1, ".", 0, 0)) > 0) FileName[nc] = 0;

 

FindPattern is part of the Formatting and I/O Library

 

 

Edit: written while Wolfgang was giving the same response Smiley Wink

Message Edited by Roberto Bozzolo on 06-07-2010 12:33 PM
Message Edited by Roberto Bozzolo on 06-07-2010 12:34 PM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 8
(5,147 Views)

Roberto,

 

I find it better to use Wolfgang's syntax in FindPattern() to search backwards for the '.' that belongs to a file extension. Otherwise if you search forwards you might find some other '.' within the body of the file name.

 

JR

0 Kudos
Message 5 of 8
(5,133 Views)

Smiley Surprised Oh my! Of course you're right!

That line came from an old app of mine I am updating these days: I will double check to correct all instances if this call in this direction.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 8
(5,101 Views)

SplitPath won't help to much, as far I can read from the documentation the file extension is kept in the outcome

0 Kudos
Message 7 of 8
(3,374 Views)

You're right, that's why we suggested to use FindPattern to search for the rightmost dot and stop the filename there.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 8
(3,369 Views)