Spring Sale! Save 30% on all books w/ code: PLANET24
Web Dev + WordPress + Security

Associate Any File with Windows Notepad in Five Seconds

In my article, Associate Extensionless Files with Notepad, I explain how to navigate the labyrinthine maze of Windows dialogue menus to assign Microsoft’s Notepad text editor as the opening application for files without extensions. In this post, I’ll show you how to associate any file type with any program (including Notepad) in less than five seconds.

Ready? Don’t blink, you’ll miss it.. ;)

Modify any file extension association in five seconds

Open the Windows command prompt and enter the following command:

assoc .extension=fileType

It’s that easy. What is happening here? Let’s break it down, just for fun:

  • assoc — Windows file-association command
  • .extension — the extension that you want to associate
  • fileType — the type of file that should be associated

Some amazing and useful facts about the assoc function:

  • Type the command “assoc” without parameters to display a list of current file extensions
  • Any fileType value shown in the aforementioned list of file extensions may be used for your files
  • If the assoc command is run with only the file-extension parameter, the function will return the current file association for that file extension
  • If nothing is specified for the fileType, the assoc function will delete the association for the given file extension
  • To learn more about the assoc function, enter the following command via the Windows command prompt: assoc /?

Here are some common fileTypes that may be useful (for an entire list, enter the “assoc” command without parameters) — you know, because you may want to open your files in something other than Notepad (although I don’t see why you would):

  • wrifile — opens in WordPad
  • Word.RTF.8 — opens in MS Word
  • Word.Document.8 — opens in MS Word
  • htmlfile — opens in your default browser

Sound good? Let’s check out a few examples.

Associate extensionless files with Notepad

Here’s how to associate extensionless files with Notepad in one swift stroke:

assoc .=txtfile

And done. Testing this method is easy because the association command works on any file. To check it, create a new file named something without an extension (e.g., “pancakes”). You will see the default Windows icon designating an unknown file type. Now run the command given above. Presto change-o rearrange-o! Your new extensionless file is now magically associated with Notepad. Go ahead, double-click on it and watch it open! Amazing :)

Associate other file types

Just because I am having so much fun with this little tutorial, let’s check out a few more examples of files that are common to us web-developer types.

.xml files

For some reason, Photoshop insists on claiming all XML files on my system. This is ridiculous, of course, but the situation is now resolved thanks to the following command:

assoc .xml=txtfile

Now, rather than launching Photoshop when I click open an XML file, the file appears instantly and ready-to-edit in Notepad. Ahhh, what a relief! :)

Raw access log files

As discussed in my article on Harvesting cPanel Raw Access Logs, checking your site’s access logs involves dealing with files that are named after your domain. For example, the access logs for Perishable Press are named “perishablepress.com”. This is fine for the server, but sadly Windows is not familiar with extensions like, “.com”, “.net”, “.org” and so on. So, rather than tediously renaming my log files, I run the following commands and call it done:

assoc .com=txtfile
assoc .net=txtfile
assoc .org=txtfile

.htaccess files

This five-second technique is perfect for HTAccess files. Off the truck, Windows can’t handle nameless files with the crazy .htaccess extension. Fortunately, we can teach Bill’s beast a little respect:

assoc .htaccess=txtfile
[ Windows Command Prompt ]
Pow! In your face, Microsoft!!! ;)

Dropping Skullz

As mentioned in the dazzling intro, this method works great for associating any type of file (i.e., any file extension) with Notepad. For web developers and designers working with the Windows operating system, this simple command-line trick is immensely helpful when dealing with the wide variety of unusual file types commonly associated with server configuration and management. Here are a few examples of files types that Windows just can’t handle without explicit instruction:

  • .htaccess
  • .ftpquota
  • mutex.lock
  • domain.tld
  • mime.types
  • httpd.conf
  • cache (no extension)

Now, rather than wasting time fighting your way through a right-click and two or three dialogue boxes every time you need to open an unknown file type in Notepad, take a few seconds to execute a simple Windows command and forget about it. Nothing could be easier!

Thank you to Ian Flournoy for sharing this incredibly useful technique!

About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
Blackhole Pro: Trap bad bots in a virtual black hole.

11 responses to “Associate Any File with Windows Notepad in Five Seconds”

  1. Hey there. I had completely forgotten about this command! I remember causing hell in middle school by tinkering with this ;)

    Just a friendly tip of advice: do NOT re-associate .EXE files!!! You can’t simply turn them back to Applications with the assoc command, and it will cause you to -not be able to run your computer-. It involves a bunch of registry fixes to get it back to normal.

    Other than that, great article – takes me back to when I first learned batch :)

    Cheers!

    -Monkey

  2. @Monkey, since .exe is executable then I Don’t need to associate it to another program.

  3. Jeff Starr 2009/06/23 2:54 pm

    Hey Monkey :) Thanks for dropping by — I am glad you enjoyed the article! Thanks for the tip on the executable files! ;)

    @Ramba: Good point there — this article is aimed at extensionless and other unassociated file types, like HTAccess, ftpquota, log files and so on.

  4. Pretty cool post. I just found your blog and wanted to say
    that I’ve really liked reading your blog posts. Anyway
    I’ll be subscribing to your blog and I hope you write again soon!

  5. @all – Haha yes, you’re right, the article -is- aimed at unassociated types :) However, you know us computer people – we’re curious ;) You never know what we might freak out and try xD

    Keep em coming, Jeff!

  6. Evil hackers of the future, take note of Monkey’s comment. You should be taking notes! :D

    Jokes aside, Jeff, thanks for another insightful tutorial! I’ve never knew that we can tinker with file-program association using command prompt, and neither did I have any idea how I managed to make Notepad open my .htaccess file by default. Perhaps it’s a few lucky clicks!

    Now I don’t have to access my cPanel to edit the .ftpquota file. Notepad will do. Thanks again for the tips! Terrific!

    p/s: Shamefully enough, I just discovered yesterday evening that you’re the co-author of Digging into WordPress! I know there’s a co-authoring dude named “Jeff” but it didn’t dawn upon me that you’re that “Jeff” *bangs head against wall* Good luck and all the best for your upcoming issue!

  7. Jeff Starr 2009/07/05 9:19 am

    @Jenna: Thanks for the feedback and even more for subscribing! :)

    @Teddy: Glad to have helped! And yes, I am the co-author “dude” named “Jeff” for the upcoming Digging into WordPress book. lol! I know I announced that here awhile ago. Perhaps, if you subscribed to my feed you could avoid such embarrassing oversights! lol – just kidding! ;)
    Cheers!

  8. That reminds me that I have to check my Google Reader after eons of conveniently forgetting that it existed. Since Twitter came into my life, I’ve got little time for RSS readers. Maybe I shall check back more often :)

  9. I am guilty of the same thing — I tend to put my feed-reading off until the last minute. Even Twitter seems like too much effort these days. They need something easier than Twitter, like maybe a chat stream that only allows 10 characters at a time. They could call it Twtr! ;) Anyways, just being silly now, should probably get back to work. Cheers :)

  10. Hi there again!

    insightful as ever, I forgot that this command existed, if I ever knew 8)

    The problems of file associations went away when I started using NexusFile by xiles.net, which has some unusual, but very convinient commands like “alt+B” to open any file in the determined editor (notepad++ in my case).

    Kind regards, mtness.

  11. Jeff Starr 2009/10/10 9:19 am

    Beautiful tip, mtness — will be checking it out =)

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
USP Pro: Unlimited front-end forms for user-submitted posts and more.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.