# Programmatically associate a file extension

**URL:** <https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174>\
**Category:** Ruby\
**Created:** [April 8, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174 "2008-04-08T16:51:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumar\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bcef8e/32.png) [@kumar\_a](https://www.ruby-forum.com/u/kumar_a)\
**Post date:** [April 8, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174/1 "2008-04-08T16:51:39Z")

</div>

Hi,

How can we programmatically associate a file extension to my program  
using Ruby.

Please send information regarding this.

Thanks in Advance,  
kumar

---

<div class="post-metadata">

**Author:** ![kumar\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bcef8e/32.png) [@kumar\_a](https://www.ruby-forum.com/u/kumar_a)\
**Post date:** [April 8, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174/2 "2008-04-08T17:01:51Z")

</div>

On Tue, Apr 8, 2008 at 4:51 PM, Kumar Ca [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> How can we programmatically associate a file extension to my program  
> using Ruby.
> 
> Please send information regarding this.
> 
> Thanks in Advance,  
> kumar

if you are on windows, use ftype and assoc commands.

[http://www.ss64.com/nt/ftype.html](http://www.ss64.com/nt/ftype.html)

---

<div class="post-metadata">

**Author:** ![kumar\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bcef8e/32.png) [@kumar\_a](https://www.ruby-forum.com/u/kumar_a)\
**Post date:** [April 8, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174/3 "2008-04-08T18:14:57Z")

</div>

Jano S. wrote:

> On Tue, Apr 8, 2008 at 4:51 PM, Kumar Ca [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,
> > 
> > How can we programmatically associate a file extension to my program  
> > using Ruby.
> > 
> > Please send information regarding this.
> > 
> > Thanks in Advance,  
> > kumar
> 
> if you are on windows, use ftype and assoc commands.
> 
> [Ftype - File type - Windows CMD - SS64.com](http://www.ss64.com/nt/ftype.html)

Thanks a lot

please give procedure for linux

---

<div class="post-metadata">

**Author:** ![kumar\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bcef8e/32.png) [@kumar\_a](https://www.ruby-forum.com/u/kumar_a)\
**Post date:** [April 8, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174/4 "2008-04-08T18:27:23Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Kumar Ca wrote:  
|  
| Thanks a lot  
|  
| please give procedure for linux

> **[Google](https://www.google.com/)**
>
> Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

Rule of Open-Source Programming #8:

Open-Source is not a panacea.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkf7nM0ACgkQbtAgaoJTgL/33QCdH9cjQa3OLZaZ92dDxYzVe/b0  
uxYAn3aOZqRB9HwEWtSNWk1URt2Y+xSU  
=S6Wa  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![kumar\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bcef8e/32.png) [@kumar\_a](https://www.ruby-forum.com/u/kumar_a)\
**Post date:** [April 8, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174/5 "2008-04-08T21:16:10Z")

</div>

Kumar Ca wrote:

> Jano S. wrote:
> 
> > On Tue, Apr 8, 2008 at 4:51 PM, Kumar Ca [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > Hi,
> > > 
> > > How can we programmatically associate a file extension to my program  
> > > using Ruby.
> > > 
> > > Please send information regarding this.
> > > 
> > > Thanks in Advance,  
> > > kumar
> > 
> > if you are on windows, use ftype and assoc commands.
> > 
> > [Ftype - File type - Windows CMD - SS64.com](http://www.ss64.com/nt/ftype.html)
> 
> Thanks a lot
> 
> please give procedure for linux

Linux does not use a “file extension” to associate a program with a  
file. Instead, scripts typically have a “shebang” line at the top. This  
is a comment to the script but, if it is present, the shell will use it  
to determine what program to execute.

> **[Shebang (Unix)](https://en.wikipedia.org/wiki/Shebang_(Unix))**
>
> In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script. It is also called sharp-exclamation, sha-bang, hashbang, pound-bang, or hash-pling.
> When a text file with a shebang is used as if it is an executable in a Unix-like operating system, the program loader mechanism parses the rest of the file's initial line as an interpreter directive. The loader executes the specified interpreter program, passing to i...

---

<div class="post-metadata">

**Author:** ![kumar\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bcef8e/32.png) [@kumar\_a](https://www.ruby-forum.com/u/kumar_a)\
**Post date:** [April 9, 2008, 3:47am UTC](https://www.ruby-forum.com/t/programmatically-associate-a-file-extension/134174/6 "2008-04-09T03:47:51Z")

</div>

In which operating system?

It’s non-trivial.

LOL

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #3 out NOW!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)
