Create Simple Script to Show / Hide File Extensions in Windows

Recently we posted a tutorial about creating script to show / hide hidden files and folders in Windows:

Create Simple Script to Show / Hide Hidden Files and Folders in Windows

Today in this tutorial, we are going to share another similar script which can be used to show / hide file extensions in Windows.

Advertisement

UPDATE: Now you can add direct option to context menus:

Add “Show/Hide File Extensions” Option in Desktop/Explorer Context Menu in Windows

Show_Hide_File_Extensions_Option_Context_Menu.png

This script when executed, checks the status of “Hide extensions of known file types” option and toggles its value. So if its set to hide file extensions, it changes the option to show file extensions and vice versa.

Simply copy paste following code in NOTEPAD and save the file with name “Show_File_Extension_On_Off.vbs” (including quotes):

FileExt = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"
Set Sh = WScript.CreateObject("WScript.Shell")
St = Sh.RegRead(FileExt)
If St = 1 Then
Sh.RegWrite FileExt, 0, "REG_DWORD"
Else
Sh.RegWrite FileExt, 1, "REG_DWORD"
End If
Sh.SendKeys("{F5}")

That’s it. You can place this script at any location like Desktop, Quick Launch toolbar and whenever you need to toggle the “Hide extensions for known file types” option, simply run the script.

Advertisement

PS: If you don’t want to create the script manually or face any problem while creating the script, you can download a ready-made script using following link:

Published in: Windows 7, Windows Vista, Windows XP

About the author: Vishal Gupta (also known as VG) has been awarded with Microsoft MVP (Most Valuable Professional) award. He holds Masters degree in Computer Applications (MCA). He has written several tech articles for popular newspapers and magazines and has also appeared in tech shows on various TV channels.

Comments

NOTE: Older comments have been removed to reduce database overhead.

  1. Very cool script, thanks.

    Is there a reason it takes 5 seconds or so for my the Explorer process (in a new or existing window) to show the change? Even when refreshing a window, or spawning a new one?

    Richard

  2. Your instructions say:

    Simply copy paste following code in NOTEPAD and save the file with name “Show_File_Extension_On_Off.vbs” (including quotes):

    TILT! No windows operating system I know of allows a person to save a file name where any character in the file name is a quote. In short you have an example above of a file name and you are instructing specifically that name be used (with quotes). Perhaps you meant to say NOT INCLUDING THE QUOTES

  3. ^^ No. The instructions are correct. When you use double-quotes while saving a file in Notepad, Notepad saves the file with the mentioned filetype. If you don’t use double-quotes, it’ll create a text file with the name Show_File_Extension_On_Off.vbs.txt

  4. I stand corrected, I see what you were doing now. This works very elegantly and fast, and is not at all similar to some other scripts I ran into on this same topic that had corequisite REG files it ran alternatingly.

    I have a couple of follow-on questions about your appl;ication, because there’s something about the nature of this created file that I don’t understand:
    It only seems to work for the directory it’s in as opposed to the entire PC, how can I change that?

    It appears that it cannot be moved to another path and work there, why is that?

    Lastly, if I put the one I saved in C:\windows and make a short cut of it there, the shortcut works when there, but take the shortcut and put it in another place and nothing happens. So there’s obviously something in the properties of this file that I don’t have a clue about.

    I’d like to have one command like this, preferably available in my Start Menu tree and have it work on the extensions in the whole PC? Can that be done?

    Thanks, Dean

  5. Thank you very much for this post!! I used your code to write a macro in VBA create buttons that can hide if shown, and show if hidden. Maybe others could use this version
    Sub ShowFileExt()
    Dim FileExt As String
    Dim Sh As Object
    Dim St As Integer

    FileExt = “HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt”
    Set Sh = CreateObject(“WScript.Shell”)
    St = Sh.RegRead(FileExt)
    If St = 1 Then
    Sh.RegWrite FileExt, 0, “REG_DWORD”
    Else
    MsgBox “Your File Extensions are already visible”
    End If
    End Sub

    Sub HideFileExt()
    Dim FileExt As String
    Dim Sh As Object
    Dim St As Integer

    FileExt = “HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt”
    Set Sh = CreateObject(“WScript.Shell”)
    St = Sh.RegRead(FileExt)
    If St = 0 Then
    Sh.RegWrite FileExt, 1, “REG_DWORD”
    Else
    MsgBox “Your File Extensions are already hidden”
    End If
    End Sub

  6. What a pleasure to have, my computer is part of a domain so each time a restart it just hides file extensions after restarts. Group policy i guess. Thanks again…

  7. Thanks a lot. Great solution for me I have finally found with you:) I had not already hoped so..
    Sorry for my English, I am from Czech Republic.

  8. The basic script can be made a bit more succinct, eliminating the If/Then with a little arithmetic:

    FileExt = “HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt”
    set Sh = WScript.CreateObject(“WScript.Shell”)
    Sh.RegWrite FileExt, abs(Sh.RegRead(FileExt) = – Sh.RegRead(FileExt)), “REG_DWORD”
    Sh.SendKeys(“{F5}”)

    Basically, we’re calculating the absolute value (0 or 1) of subtracting whatever value we read from the Registry from itself. If the value read from the Registry is 1, the result of 0 is written to the Registry, and if the existing value is 0, 1 subtracted from that is -1, the absolute value being 1 is written to the Registry.

    Since you’re accessing the Registry setting three times, it makes sense to load a variable for it.

Leave a Comment

Your email address will not be published. Required fields are marked *

NOTE: Your comment may not appear immediately. It'll become visible once we approve it.