469,353 Members | 2,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

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

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

Nov 21 '05 #1
4 9363
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
"lcifers" <lc*****@yahoo.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.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

Nov 21 '05 #2
HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\Advance
d

HideFileExt

0 = Show

1 = Hide

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #3
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

"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

Nov 21 '05 #4
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
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Stephen Oakes | last post: by
2 posts views Thread by | last post: by
3 posts views Thread by Richard Rudie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.