Posts Tagged ‘filename’

Extract filename from string

Thursday, February 5th, 2009

The following Perl program extracts a filename from a given string. It takes one string parameter.


Syntax:
Perl FilenameExtract.pl Paramerter1

Example:
Perl FilenameExtract.pl http://www.csatechconsulting.com/images/WashingtonFlags.JPG

Returns: WashingtonFlags.JPG

FilenameExtract.pl:

if (@ARGV ==0) { print "You must include one parametern"; exit(); } $_ = $ARGV[0]; $wholePath = ~m{([^/]*)$}; $fileName = $1; print "$1n";