Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API to toggle "Show hidden files, folders and drives"

Is there a function in Windows API to toggle the "Show hidden files, folders and drives" option in Windows Explorer (Tools >> Folder Options... >> View tab).

I know of a related registry key, but changing that would not have immediate effect. The key is: HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/Advanced/Hidden

Trying to do this from C#, but the question is not language-specific.

like image 292
dbkk Avatar asked Mar 25 '10 10:03

dbkk


People also ask

How can you display hidden files and folders?

Open File Explorer from the taskbar. Select View > Options > Change folder and search options. Select the View tab and, in Advanced settings, select Show hidden files, folders, and drives and OK.

How do I toggle a hidden folder?

Select the Start button, then select Control Panel > Appearance and Personalization. Select Folder Options, then select the View tab. Under Advanced settings, select Show hidden files, folders, and drives, and then select OK.

How do I make hidden files visible in CMD?

To show hidden files, you need to include the /a:h modifier in that command. So, dir /a:h C:your-folder will do the trick. CMD also has specific commands for showing directories and folders. /a:d shows all hidden directories, and /a shows hidden folders.

What command will display the hidden files?

Way 2: show hidden files with attrib command Open Command Prompt as you do in Way 1. 2. Type attrib -h -r -s /s /d F:\*. * and press Enter to unhide hidden files in drive F.


2 Answers

You could try the options the OP in this thread suggests, that is:

Either

 SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);

or

 RefreshPolicyEx(False, RP_FORCE);

or

 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, integer(pchar('Policy')), SMTO_NORMAL or SMTO_ABORTIFHUNG, 5000, c1);

These are not in the .NET C# API, so you'll have to use DllImport

Edit: formatting

like image 173
anorm Avatar answered Oct 12 '22 23:10

anorm


In addition to the comment I've added to the original question - if you're doing this so that, for instance, the OpenFileDialog you're about to pop open shows these files - don't do it.

In that case, you're better P/Invoking GetOpenFileName, and setting the appropriate option (OFN_FORCESHOWHIDDEN (see enum for a related subject) in the flags of the OpenFileName structure.

That way you're only affecting your application, at the appropriate time

like image 38
Damien_The_Unbeliever Avatar answered Oct 13 '22 00:10

Damien_The_Unbeliever