Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to remove file extension [duplicate]

What is the shortest way to remove file extension? this is what I have tried:

file = "/home/usr/my_file.xml" file = File.basename(file) file.slice! File.extname(file)   #=> my_file 
like image 203
tokhi Avatar asked Jan 03 '14 10:01

tokhi


People also ask

How do I remove a double filename extension?

Open File Explorer and click View tab, Options. In Folder Options dialog, move to View tab, untick Hide extensions for known file types option, OK. Then you will se file's extension after its name, remove it.

Does Windows 10 have a duplicate file remover?

Answer: No, Windows 10 does not have a duplicate finder in it yet.


1 Answers

Read the documentation of File::basename :

basename(file_name [, suffix] ) → base_name

Returns the last component of the filename given in file_name, which can be formed using both File::SEPARATOR and File::ALT_SEPARETOR as the separator when File::ALT_SEPARATOR is not nil. If suffix is given and present at the end of file_name, it is removed.

file = "/home/usr/my_file.xml" File.basename(file,File.extname(file)) # => "my_file" 
like image 150
Arup Rakshit Avatar answered Oct 13 '22 18:10

Arup Rakshit