This is useful for conditional branching by file extension, or when you want to apply a filter.
It simply looks like this
var GetFileExtension = (path) => path.split('/').pop().split('\\').pop().split('.').pop();
The file name is retrieved first, and then after the extension "."(dot) are obtained.
An example of a file that does not have "." is not present in the file name, for example, if the file is called "hosts", then the "hosts" t will be retrieved.
The following is an example of use.
var GetFileExtension = (path) => path.split('/').pop().split('\\').pop().split('.').pop(); var fullpath_windows = "C:\\02_data\\01_dev\\03_nodachisoftweb\\contents\\sample.png"; var fullpath_unix = "/home/amaji/sample.png"; console.log("Using on Windows :" + GetFileExtension(fullpath_windows)); console.log("Using on Linux :" + GetFileExtension(fullpath_unix));
Here is the result.
Using on Windows :png Using on Linux :png
The extension of the image file, "png", has been retrieved as a string.
Thank you for your message.
Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.Twitter:@NodachiSoft_engName:
Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".Name: