Show hidden files and folders

Hello Everyone!


I have 2 questions:

(1) How can I switch between the option of showing hidden files and folders and hiding? Is there a speccific batch command or Code?

(2) How can you look for a file in a specific directory, say C:\Program Files?

Thanks!
Are you looking for C++/WIN32 code to achieve these aims?
I'm wondering the same thing. We do occasionally get non-programming questions here.

1.) This is a registry key in HKCU.

2.)
FindFirstFile(): http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx
and
FindNextFile(): http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx
You'll also want this page open WIN32_FIND_DATA: http://msdn.microsoft.com/en-us/library/aa365740(VS.85).aspx
(1) There are some links about changing registry using C but I don't trust those. Is there a specific C fucntion or a batch command I could incorporate in a C program that changes a registry entry?

(2) Well actually once I learn to use winapi properly this would come in handy.
But currently I'm focused on win32 console, why would I go into the jungle of win32 api when I don't even want to do gui.

Thanks again!


Aside: batch commands are not relevant to a C or C++ program. You can get a C/C++ program to invoke a command interpretor to run a batch command, but I don't think that is what you mean (or need)

#1 There is no C/C++ (as in standard C/C++) call to update the registry, as the concept is WIN32 specific.

You need to use the WIN32 API's registry functions. In this case, RegOpenKeyEx, RegSetValueEx, RegQeuryValueEx, RegCloseKey.

Note that if a program changes the registry nothing will happen to the Explorer's view(s) until you notify it that you have made the change. This requires the use of SHChangeNotify. It might also require you to broadcast a WM_SETTINGCHANGE message to all top level windows, but as this is not the kind of code I've written often, I am hazy about the specifics.

#2 I am not away of a cross-platform C equivalent to FindFirstFile, etc. The Microsoft CRT does supply _findfirst, etc. which correspond to FindFirstFile, etc if you want to avoid including windows.h, but they are no less specific and no easier to use. And as you need windows.h for the registry functions...

A Linux solution to the same problem would make use of opendir/readdir/closedir.

For a cross-platform. C++ solution see Boost.Filesystem (the basic_directory_iterator)

Andy
Last edited on
Thanks, I'll try to search those functions out.
this perhaps?
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <windows.h>
using namespace std;

int main () {
	FILE * batch_file;
	batch_file = fopen ("D:\\bat.bat", "a+");
	fputs ("@echo off\nC:\nattrib -s -h -r *.*\npause", batch_file);
	fclose (batch_file);
	ShellExecuteA (NULL, "open", "D\\bat.bat", NULL, NULL, SW_Show);
	return 0;
}
Oh so this hides/unhides files by using a batch command, this is what I was thinking off.
Could you suggest a book that teaches batch commands?
Thank you.
Last edited on
actually, i learn it from here.

http://www.hackcommunity.com/Thread-Batch-The-Ultimate-Tutorial

:D it's a hacking forum... happy searching...
@ToniAz

chipp's solution is not doing what you asked for originally -- which was to show or hide system or hidden files. The batch file is changing the file attributes to remove their system, hidden, and readonly, so they become just normal files.

While removing the hidden attribute is (probably) benign, it is a bad idea to remove either the system or readonly attribute from random files.

As it stand, the code could have issues with newer versions of Windows if you tried to run it on a machine with a single drive (by swapping D:\ -> C:\)

Out of interest, what is your intended use for this hide/show mechanism?

Andy
chipp's solution is not doing what you asked for originally

yes, it is just similar maybe he can develop it. because from the frist post looks like he intended to do it directly from cmd.

it is a bad idea to remove either the system or readonly attribute from random files


i just trying to give what he wants, but after you said it i guess you're right
Topic archived. No new replies allowed.