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.

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.

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:

Download Script

Also check:

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





Share this article: Facebook | Twitter | Google+ | Reddit | Tell a friend

Posted in: Windows 7, Windows Vista, Windows XP


Other similar articles that may interest you


Comments

  • 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

  • VG

    ^^ It depends upon Windows how much time does it take to apply changes.

  • omg , this was a great input, than you.

  • 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

  • VG

    ^^ 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

  • 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

  • VG

    ^^ The script will work from any location. You can put it anywhere you want.

  • 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

  • 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...

  • 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.

  • 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

(required)