Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show and hide hidden files and directories 1

Status
Not open for further replies.

WilliamCalm

Programmer
Feb 6, 2004
9
CN
hi friends, I wish to know which API function does the job of show and hide the hidden files and directories. I would be very much appriciate if a simple example is also provides. Thanks a lot
 
I believe the functions you are interested in are GetFileAttributes and SetFileAttributes, here's an example:

Code:
  char fname[10] = "test.txt";
  DWORD dwFileAttributes;

  // the following removes the hidden attribute
  dwFileAttributes = GetFileAttributes((LPCSTR) fname);
  dwFileAttributes &= ~FILE_ATTRIBUTE_HIDDEN;
  SetFileAttributes((LPCSTR) fname,dwFileAttributes);

  // the following sets the hidden attribute
  dwFileAttributes = GetFileAttributes((LPCSTR) fname);
  dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;
  SetFileAttributes((LPCSTR) fname,dwFileAttributes);

Hope this helps, Good luck.
 
Thank you very much, and how about the directories? What are the functions to handle them and are they used in the similar way?
 
> Thank you very much, and how about the directories?

The same functions are used for directories in exactly the same manner as above. Just copy the directory name into fname instead of a file name.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top