How to get extension of file in perl, PHP,BASH etc

How to get a file extension
How to get a file extension in PHP:

$ext = pathinfo($file_name, PATHINFO_EXTENSION);
How to get a file extension in Perl:

my $ext = ($file_name =~ m/([^.]+)$/)[0];
How to get a file extension in Ruby:

ext = File.extname(file_name)
How to get a file extension in Bash:

ext=${file_name##*.}
name=${file_name%.*}
How to get a file extension in Python:

import os
ext = os.path.splitext(file_name)[1]

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: