Forums Register Login

remove extension from file name

+Pie Number of slices to send: Send
Hi All,

I can get the name of a file using getName(), but I want to remove the extension

Should I just write a substring to extract a filename, or is there a method in the API to do so.

Name: file.txt
I want to remove the .txt to extract just "file"

This code does the job do for:

[ August 11, 2005: Message edited by: Cathy Song ]
+Pie Number of slices to send: Send
There are other ways to do it, but there's no "removeExtension" method. Your way is as good as any other.
+Pie Number of slices to send: Send
You might want lastIndexOf. I have some files that include versions like

BogWater1.3.1.exe
+Pie Number of slices to send: Send
The simplest version would be



The assumption is that regardless of how mant dots you have in the file name, the extension is always after the last dot.
+Pie Number of slices to send: Send
So to extract the filename using the same approach as Sathya:
+Pie Number of slices to send: Send
Thanks a lot!

-Cathy
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 10217 times.
Similar Threads
Substring
NumberFormatException Error
Referencing to another object
Text File Parse - Code comments please
getParent inquiry
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:03:04.