Home All Groups Group Topic Archive Search About

Determine if "Hide extensions for known file types" is active

Author
15 Apr 2005 8:41 PM
lcifers
Is there a way, through VB.NET, to determine if the user has selected
this option? I am writing an application that does some string
functions to rename files, and the file names get chopped up if the
expected extension is not returned.

I can write another function to get around this, but if there is a
clean way to determine the state of that toggle I would rather do that.
I may need this again in the future and don't want to always write
custom string functions to get around it.

TIA.

- Luther

Author
15 Apr 2005 10:02 PM
Richard Myers
Thats very interesting i didn't realise this setting had any effect. I
thought it affected the UI portion of Windows Explorer only, not the actual
output from the file system. Whatever the setting it will be in the
registry so you can check there. If your asking which registry key then Im
not sure but i reckon you could probably Google it in under 5 mins.

Richard


Show quoteHide quote
"lcifers" <lcif***@yahoo.com> wrote in message
news:1113597680.632586.82470@l41g2000cwc.googlegroups.com...
> Is there a way, through VB.NET, to determine if the user has selected
> this option? I am writing an application that does some string
> functions to rename files, and the file names get chopped up if the
> expected extension is not returned.
>
> I can write another function to get around this, but if there is a
> clean way to determine the state of that toggle I would rather do that.
> I may need this again in the future and don't want to always write
> custom string functions to get around it.
>
> TIA.
>
> - Luther
>
Author
15 Apr 2005 11:09 PM
Crouchie1998
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advance
d

HideFileExt

0 = Show

1 = Hide

Crouchie1998
BA (HONS) MCP MCSE
Author
16 Apr 2005 12:44 AM
Dennis
I use the below recursive routine to get a list of files in a directory and
it returns the extension as part of the file name in the List object even if
the "hide known file types" is checked:

  Private Sub ListFiles(ByRef list As ArrayList, ByVal sPath As String,
ByVal searchpattern As String, ByVal returnpath As Boolean, ByVal chksubdir
As Boolean)
        Dim di As System.IO.DirectoryInfo
        Try
            di = New System.IO.DirectoryInfo(sPath)
            For Each fi As System.IO.FileInfo In di.GetFiles
                If searchpattern = Nothing OrElse fi.Name.ToLower Like
searchpattern Then
                    If returnpath Then list.Add(fi.FullName) Else
list.Add(fi.Name)
                End If
            Next
            If chksubdir Then
                For Each diSub As System.IO.DirectoryInfo In di.GetDirectories
                    ListFiles(list, diSub.FullName, searchpattern,
returnpath, chksubdir)
                Next
            End If
        Catch ex As Exception
            list = Nothing
            errmsg = ex.Message
            errno = Err.Number
        End Try
    End Sub

Show quoteHide quote
"lcifers" wrote:

> Is there a way, through VB.NET, to determine if the user has selected
> this option? I am writing an application that does some string
> functions to rename files, and the file names get chopped up if the
> expected extension is not returned.
>
> I can write another function to get around this, but if there is a
> clean way to determine the state of that toggle I would rather do that.
> I may need this again in the future and don't want to always write
> custom string functions to get around it.
>
> TIA.
>
> - Luther
>
>
Author
16 Apr 2005 1:37 AM
Crouchie1998
Just check against (read) the registry key I pasted before.

I must say your recursive routine is quite long

You don't need

errmsg = ex.Message
errno = Err.Number

because its already been checked using the Try - Catch - End Try block. You
could say:

MessageBox.Show(ex.ToString, Me.Text)

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

Private Function IsExtensionShown() As Integer
Dim strKey As String = ""
Dim reg As RegistryKey
Dim intTemp As Integer

Try
    reg = Registry.CurrentUser.OpenSubKey(strKey, True)
    If Not (reg Is Nothing) Then
        intTemp = reg.GetValue("HideFileExt")
    End If
Catch ex As Exception
    ' Access denied error (security)
    MessageBox.Show(ex.ToString)
Finally
    If Not reg Is Nothing Then reg.Close()
End Try

Return intTemp

End Function

Return Values:
--------------

0 = Show File Extensions
1 = Hide File Extensions

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

Crouchie1998
BA (HONS) MCP MCSE
Author
16 Apr 2005 12:34 PM
Dennis
It's a part of my overall application and a part of a class that uses these
variables for error handling.

Show quoteHide quote
"Crouchie1998" wrote:

> Just check against (read) the registry key I pasted before.
>
> I must say your recursive routine is quite long
>
> You don't need
>
> errmsg = ex.Message
> errno = Err.Number
>
> because its already been checked using the Try - Catch - End Try block. You
> could say:
>
> MessageBox.Show(ex.ToString, Me.Text)
>
> -------------------------------------------
>
> Private Function IsExtensionShown() As Integer
> Dim strKey As String = ""
> Dim reg As RegistryKey
> Dim intTemp As Integer
>
> Try
>     reg = Registry.CurrentUser.OpenSubKey(strKey, True)
>     If Not (reg Is Nothing) Then
>         intTemp = reg.GetValue("HideFileExt")
>     End If
> Catch ex As Exception
>     ' Access denied error (security)
>     MessageBox.Show(ex.ToString)
> Finally
>     If Not reg Is Nothing Then reg.Close()
> End Try
>
> Return intTemp
>
> End Function
>
> Return Values:
> --------------
>
> 0 = Show File Extensions
> 1 = Hide File Extensions
>
> --------------
>
> Crouchie1998
> BA (HONS) MCP MCSE
>
>
>
Author
16 Apr 2005 12:35 PM
Dennis
Note the routine also has the option of returning the full path in the list
array as well as checking subdirectories or not.

Show quoteHide quote
"Crouchie1998" wrote:

> Just check against (read) the registry key I pasted before.
>
> I must say your recursive routine is quite long
>
> You don't need
>
> errmsg = ex.Message
> errno = Err.Number
>
> because its already been checked using the Try - Catch - End Try block. You
> could say:
>
> MessageBox.Show(ex.ToString, Me.Text)
>
> -------------------------------------------
>
> Private Function IsExtensionShown() As Integer
> Dim strKey As String = ""
> Dim reg As RegistryKey
> Dim intTemp As Integer
>
> Try
>     reg = Registry.CurrentUser.OpenSubKey(strKey, True)
>     If Not (reg Is Nothing) Then
>         intTemp = reg.GetValue("HideFileExt")
>     End If
> Catch ex As Exception
>     ' Access denied error (security)
>     MessageBox.Show(ex.ToString)
> Finally
>     If Not reg Is Nothing Then reg.Close()
> End Try
>
> Return intTemp
>
> End Function
>
> Return Values:
> --------------
>
> 0 = Show File Extensions
> 1 = Hide File Extensions
>
> --------------
>
> Crouchie1998
> BA (HONS) MCP MCSE
>
>
>
Author
17 Apr 2005 12:36 AM
lcifers
Thanks for the input. I am working with another Windows application
that has a function that returns the filename as part of its API. So
while the setting may not matter in your application, I can tell you
without a doubt that it does with this particular application. I'll
query the registry key as suggested.

As always, thanks for the help!

- Luther
Author
17 Apr 2005 12:42 AM
Crouchie1998
Pleasure

Crouchie1998
BA (HONS) MCP MCSE