|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Determine if "Hide extensions for known file types" is activeIs 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 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 > HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advance
d HideFileExt 0 = Show 1 = Hide Crouchie1998 BA (HONS) MCP MCSE 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 > > 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 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 > > > 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 > > > 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
An absence of IntelliSense in this situation
What scope is best for defining Enum type? VB6 to VB.Net Conversion How to overload method of third party component? creating an array as property of a class Making trial version Limiting the directories somebody can browse to..... Passing parameters to Data Adapter Creating a custom log Hierarchal recordset |
|||||||||||||||||||||||