RSS

Gets File Extension

Sun, Jun 1, 2008

Programming

Here we can compare the syntax of these languages, how do they get file extension.

我们可以比较一下php, perl, ruby, bash, python的语法,同样的功能是如何实现的。

in PHP:

$ext = pathinfo($file_name, PATHINFO_EXTENSION);

in Perl:

my $ext = ($file_name =~ m/[^.]+$/)[0];

in Ruby:

ext = File.extname(file_name)

in Bash:

ext=${file_name#*.}
name=${file_name%.*}

in Python:

import os
ext = os.path.splitext(file_name)[1]
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • E-mail this story to a friend!
  • Haohao
  • Reddit
, , , ,

This post was written by:

Jay - who has written 38 posts on Activars.


Contact the author

Leave a Reply