locked
Hidden files/folders? C# 2.0 RRS feed

  • Question

  • I need to know how I can search through a folder or directory and NOT see all the hidden files/folders.

    C# 2.0 Windows App
    Wednesday, February 28, 2007 7:57 PM

Answers

  • Hi, dadon

    The openFileDialog didnot show the hidden files, so consider changing the file's hidden attribute.

    Use File.SetAttribute method, and you can see the example for this purpose: http://msdn2.microsoft.com/en-us/library/system.io.file.setattributes(VS.80).aspx

    If you have further problems, pls feel free to let me know.

    Thank you.

    Friday, March 2, 2007 2:49 AM
  • Hi, dadon

    As far as I know File class does not have GetFiles method, did you misspell it?

    Anyway, if you've got the FileInfo of the file you don't need to call File.SetAttributes method, you can just set the FileInfo.Attributes property.

    For example:

                FileInfo info = ...
                info.Attributes = info.Attributes | FileAttributes.Hidden;

    Thank you

    Monday, March 5, 2007 2:13 AM
  • Hi, dadon

    You can use for example

                FileInfo info =...
                
                if ((info.Attributes | FileAttributes.Hidden) == info.Attributes)

                //if the file is hidden it return true

                else

                //the file is not hidden

    Thank you

    Tuesday, March 6, 2007 1:45 AM

All replies

  • Hi,

    What exact process you want to do?

    Does openFileDialog work for you?

    Thanks

    Thursday, March 1, 2007 5:47 AM
  • I want to display a directory I.E. My Documents and when I display the files and folders, I want to have a method which DOESN'T display the hidden files and folders and vice versa
    Thursday, March 1, 2007 8:34 PM
  • Hi, dadon

    The openFileDialog didnot show the hidden files, so consider changing the file's hidden attribute.

    Use File.SetAttribute method, and you can see the example for this purpose: http://msdn2.microsoft.com/en-us/library/system.io.file.setattributes(VS.80).aspx

    If you have further problems, pls feel free to let me know.

    Thank you.

    Friday, March 2, 2007 2:49 AM
  • Do you know how to set the attributes of the files to hidden when you use the .GetFiles method?

    System.IO.DirectoryInfo file = new System.IO.DirectoryInfo(newnode);
    System.IO.FileInfo[] Files = File.GetFiles("*.*");
    Friday, March 2, 2007 7:13 PM
  • Hi, dadon

    As far as I know File class does not have GetFiles method, did you misspell it?

    Anyway, if you've got the FileInfo of the file you don't need to call File.SetAttributes method, you can just set the FileInfo.Attributes property.

    For example:

                FileInfo info = ...
                info.Attributes = info.Attributes | FileAttributes.Hidden;

    Thank you

    Monday, March 5, 2007 2:13 AM
  • If you declare the file as hidden like the above code, how do you find out if the file is "Hidden" in code.

    Sorry my code was unclear. Heres the code again in a simpler form

    System.IO.DirectoryInfo Folder123 = new System.IO.DirectoryInfo("qwerty.txt");
    System.IO.FileInfo[] Files = Folder123 .GetFiles("*.*");
    Monday, March 5, 2007 11:13 AM
  • I found the answer. It was one of the earlier posts. I still want to know if you can check the attributes in the .GetFiles() method under System.IO.DIrectoryInfo.

    Thanks for your time and help
    Monday, March 5, 2007 11:24 AM
  • Hi, dadon

    You can use for example

                FileInfo info =...
                
                if ((info.Attributes | FileAttributes.Hidden) == info.Attributes)

                //if the file is hidden it return true

                else

                //the file is not hidden

    Thank you

    Tuesday, March 6, 2007 1:45 AM