Jump to content

Func To Control Windows Show/hide File Extensions


Lilla
 Share

Recommended Posts

OK, I found and fixed the problem. It seems to work good for me.

Check it out, let me know what you think.

This function is useful when using Windows Matching on applications

that include the file name in the title such as: Notepad, Word, Excel, etc.

I added a demo, so just save, uncomment the demo line, and run

FolderOptions.au3

---------------------

#include-once

;Demo()

; ------------------------------------------------------------------------------

;

; AutoIt Version: 3.0

; Language: English

; Description: Functions that assist with Windows Folder Options.

;

; ------------------------------------------------------------------------------

;===============================================================================

;

; Description: Query or set Windows option to Show/Hide file extensions

; Syntax: _ShowHideFileExt( $iParm )

; Parameter(s): $iParm - the action you want the function to perform

; -1 = query. Return the current setting for extensions.

; 0 = show. Assure extensions are showing, set if necessary.

; 1 = hide. Assure extensions are hiding, set if necessary.

; Requirement(s): None

; Return Value(s): On Success - returns the current setting (0=Show 1=Hide)

; On Failure - returns -1 and sets @error = 1

; if there is an error reading the registry

; or if a bad parameter is passed.

; Author(s): Lilla Renfro Slater <lilla@earthlink.net>

; Notes: For all versions of windows. Tested under Windows XP and 98.

; Under Windows XP, "Hide extensions for known files" option (default = enabled)

; is located on Control Panel > Folder Options > View tab.

;

; This function is helpful when using AutoIt Windows Matching with applications

; that show the file name on the title bar, such as: Notepad, Word, Excel, etc.

;

; For example,

; eula - Notepad (window title when extensions are set to hide)

; eula.txt - Notepad (window title when extensions are set to show)

;

; Example 1: This code assures that extensions are showing.

; _ShowHideFileExt(0)

; run('notepad.exe c:\windows\system32\eula.txt')

; WinWaitActive('eula.txt - Notepad')

;

; Example 2: This code adapts to the existing Show/Hide File Ext. setting

; $result = _ShowHideFileExt(-1) ; return the current setting

; run('notepad.exe c:\windows\system32\eula.txt')

; If $result = 0 Then ;extensions are showing

; $ext='.txt'

; Else ;extensions are hidden

; $ext=''

; EndIf

; WinWaitActive('eula' & $ext & ' - Notepad')

;

; Example 3: This code assures that extensions are showing, and

; restores the initial setting when done.

; Dim $query = -1, $show =0 , $hide = 1

; $initial = _ShowHideFileExt($query)

; If $initial <> $show then

; $flag=1

; _ShowHideFileExt($show)

; EndIf

; run('notepad.exe c:\windows\system32\eula.txt')

; WinWaitActive('eula.txt - Notepad')

; msgbox(0,'debug',"observe that Notepad's title line INCLUDES file extension")

; WinClose('eula.txt - Notepad')

; If $flag=1 then _ShowHideFileExt($initial) ;restore initial setting

;

;===============================================================================

Func _ShowHideFileExt($iParm)

Local $key, $ret, $query = -1, $show = 0, $hide = 1

$key = RegRead( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced', 'HideFileExt' )

If @error Then

$ret = -1

SetError( 1 )

Else

Select

Case $iParm = $show

If $key = $hide Then ;hide => show

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", 0)

;EnvUpdate() - doesn't appear to make a difference

EndIf

$ret = $show

Case $iParm = $hide

If $key = $show Then ;show => hide

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", 1)

;EnvUpdate() - doesn't appear to make a difference

EndIf

$ret = $hide

Case $iParm = $query

$ret = $key

Case Else

$ret = -1

SetError( 1 )

EndSelect

EndIf

Return $ret

EndFunc ;==>_ShowHideFileExt

Func Demo() ; toggle hide/show file extensions

Local $query = -1, $show = 0, $hide = 1

For $i = 1 To 2

$initial = _ShowHideFileExt ($query)

;toggle setting for demo purposes

If $initial = 1 Then

$flag = 1

$now = _ShowHideFileExt (0)

ElseIf $initial = 0 Then

$flag = 1

$now = _ShowHideFileExt (1)

EndIf

Run('notepad.exe c:\windows\system32\eula.txt')

If $now = 1 Then

WinWaitActive('eula - Notepad')

MsgBox(0, @scriptname, "observe that Notepad's title line does NOT include file extension")

WinClose('eula - Notepad')

ElseIf $now = 0 Then

WinWaitActive('eula.txt - Notepad')

MsgBox(0, @scriptname, "observe that Notepad's title line INCLUDES file extension")

WinClose('eula.txt - Notepad')

EndIf

Next

EndFunc ;==>Demo

Edited by Lilla
Link to comment
Share on other sites

  • 3 years later...

wow this is old. thanks

formatted:

#include-once

Demo()

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language: English
; Description: Functions that assist with Windows Folder Options.
;
; ------------------------------------------------------------------------------


;===============================================================================
;
; Description: Query or set Windows option to Show/Hide file extensions
; Syntax: _ShowHideFileExt( $iParm )
; Parameter(s): $iParm - the action you want the function to perform
;   -1 = query. Return the current setting for extensions.
;    0 = show. Assure extensions are showing, set if necessary.
;    1 = hide. Assure extensions are hiding, set if necessary.
; Requirement(s): None
; Return Value(s): On Success - returns the current setting (0=Show 1=Hide)
; On Failure - returns -1 and sets @error = 1
;   if there is an error reading the registry
;   or if a bad parameter is passed.
; Author(s): Lilla Renfro Slater <lilla@earthlink.net>
; Notes: For all versions of windows. Tested under Windows XP and 98.
;   Under Windows XP, "Hide extensions for known files" option (default = enabled)
;   is located on Control Panel > Folder Options > View tab.
;
; This function is helpful when using AutoIt Windows Matching with applications
; that show the file name on the title bar, such as: Notepad, Word, Excel, etc.
;
; For example,
;   eula - Notepad (window title when extensions are set to hide)
;   eula.txt - Notepad (window title when extensions are set to show)
;
; Example 1: This code assures that extensions are showing.
;   _ShowHideFileExt(0)
;   run('notepad.exe c:\windows\system32\eula.txt')
;   WinWaitActive('eula.txt - Notepad')
;
; Example 2: This code adapts to the existing Show/Hide File Ext. setting
;   $result = _ShowHideFileExt(-1) ; return the current setting
;   run('notepad.exe c:\windows\system32\eula.txt')
;   If $result = 0 Then ;extensions are showing
;       $ext='.txt'
;   Else ;extensions are hidden
;       $ext=''
;   EndIf
;   WinWaitActive('eula' & $ext & ' - Notepad')
;
; Example 3: This code assures that extensions are showing, and
;   restores the initial setting when done.
;   Dim $query = -1, $show =0 , $hide = 1
;   $initial = _ShowHideFileExt($query)
;   If $initial <> $show then
;       $flag=1
;       _ShowHideFileExt($show)
;   EndIf
;   run('notepad.exe c:\windows\system32\eula.txt')
;   WinWaitActive('eula.txt - Notepad')
;   msgbox(0,'debug',"observe that Notepad's title line INCLUDES file extension")
;   WinClose('eula.txt - Notepad')
;   If $flag=1 then _ShowHideFileExt($initial) ;restore initial setting
;
;===============================================================================

Func _ShowHideFileExt($iParm)
    Local $key, $ret, $query = -1, $show = 0, $hide = 1
    $key = RegRead( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced', 'HideFileExt' )
    If @error Then
        $ret = -1
        SetError( 1 )
    Else
        Select
        Case $iParm = $show
            If $key = $hide Then ;hide => show
                RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", 0)
                ;EnvUpdate() - doesn't appear to make a difference
            EndIf
            $ret = $show
        Case $iParm = $hide
            If $key = $show Then ;show => hide
                RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", 1)
                ;EnvUpdate() - doesn't appear to make a difference
            EndIf
            $ret = $hide
        Case $iParm = $query
            $ret = $key
        Case Else
            $ret = -1
            SetError( 1 )
        EndSelect
    EndIf
    Return $ret
EndFunc ;==>_ShowHideFileExt

Func Demo() ; toggle hide/show file extensions
    Local $query = -1, $show = 0, $hide = 1
    For $i = 1 To 2
        $initial = _ShowHideFileExt ($query)
        ;toggle setting for demo purposes
        If $initial = 1 Then
            $flag = 1
            $now = _ShowHideFileExt (0)
        ElseIf $initial = 0 Then
            $flag = 1
            $now = _ShowHideFileExt (1)
        EndIf
        Run('notepad.exe c:\windows\system32\eula.txt')
        If $now = 1 Then
            WinWaitActive('eula - Notepad')
            MsgBox(0, @scriptname, "observe that Notepad's title line does NOT include file extension")
            WinClose('eula - Notepad')
        ElseIf $now = 0 Then
            WinWaitActive('eula.txt - Notepad')
            MsgBox(0, @scriptname, "observe that Notepad's title line INCLUDES file extension")
            WinClose('eula.txt - Notepad')
        EndIf
    Next
EndFunc ;==>Demo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...