Cynosure.X International LLC

: :

Add Comment | Related Links | TrackBack
Related Content (GPL)

The UNIX command "basename" is a wonderful tool. When you specify a path, it will tell you the file name. If you specify a suffix (or an extension), it can trim that from the file name. The only problem is that there isn't an UNIX command for telling you the extension of a file. And if you don't know the extension of the file, then you can't tell "basename" the correct suffix to remove.

So I have written this script. This script can tell you the extension of the file name you specified as a path. If the file name has no extension, then it returns an empty string. takes advantage of the (GPL) and the Bourne shell scripts. These scripts are all available on this site. So to use, you will need to download the these other scripts if you don't already have them. is distributed as executable source code under the GNU General Public License. Please see the license agreement elsewhere on this site.

Attached File: (392 B)

Chieh Cheng
Wed, 27 Feb 2008 02:25:52 +0000

After using this script for a few days, I found two cases where this script would fail: 1) when the file name contains one or more spaces; and 2) when the file name has more than one period.

So I have fixed those problem in this latest version of Now the spaces will not effect the output. And when there is more than one periods, returns the extension from the end of the last period. In addition, the first period in file names that starts with a period are ignored.

Usage "path"



> .Xsession

> .xinitrc.solaris

> .vgalaxy.1.vr

> "Firefox 0.9.3.exe"

Attached File: 1 - (567 B)

Chieh Cheng
Mon, 03 Mar 2008 21:25:28 +0000

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

Add Comment

Spam Control | * indicates required field
Your Name: *
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 9 + 5?
Click button only once, please!


TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.

Send Ping | TrackBack URL | Spam Control

No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here.

Messages, files, and images copyright by respective owners.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

51 Users Online

Hacking Digital Cameras
Fun for Photographers

Amazon Associate

Copyright © 1996 - 2024. All Rights Reserved.