06-07-2010 05:09 AM
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
06-07-2010 05:16 AM
06-07-2010 05:29 AM
....edit time has expired, ![]()
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.
06-07-2010 05:32 AM - edited 06-07-2010 05:34 AM
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
06-07-2010 06:51 AM
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
06-08-2010 03:56 AM
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.
03-20-2019 04:31 AM
SplitPath won't help to much, as far I can read from the documentation the file extension is kept in the outcome
03-20-2019 06:24 AM
You're right, that's why we suggested to use FindPattern to search for the rightmost dot and stop the filename there.