none
Why some methods of GetFileSystemInfos fail? RRS feed

  • Question

  • Hello,

     I can not find any reason why the following methods fail and some do not. 

     

    DirectoryInfo di = new DirectoryInfo( @"C:\" );
    
    FileSystemInfo[] fsi = null;
    
    try
    {
        // fails
        //
        // fsi = di.GetFileSystemInfos( "*.*", SearchOption.AllDirectories );
        // fsi = di.GetFileSystemInfos( "*", SearchOption.AllDirectories );
    
        // success
        //
        // fsi = di.GetFileSystemInfos( "*", SearchOption.TopDirectoryOnly );
        // fsi = di.GetFileSystemInfos( "*.*" );
    
        fsi = di.GetFileSystemInfos();
    }

    Results:

     

     Is the issues about nested folders? Can anyone explain? Thanks :)

    Tuesday, October 24, 2017 7:39 AM

Answers

  • Hi User3DX,

    Thank you for posting here.

    >> // fails

        //
        // fsi = di.GetFileSystemInfos( "*.*", SearchOption.AllDirectories );
        // fsi = di.GetFileSystemInfos( "*", SearchOption.AllDirectories );

    AllDirectories mean includes the current directory and all its subdirectories in a search operation. This option includes reparse points such as mounted drives and symbolic links in the search. Not all the directories will allow to you access. It is more related to permissions.

    TopDirectoryOnly mesn it includes only the current directory in a search operation. It is a default value of this parameter. Hence it is easily to succeed.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by User3DX Thursday, October 26, 2017 8:44 AM
    Thursday, October 26, 2017 6:36 AM
    Moderator

All replies

  • Maybe because some of the directories are not allowed for the program to access ?
    Tuesday, October 24, 2017 8:08 AM
  • Hi User3DX,

    Thank you for posting here.

    >> // fails

        //
        // fsi = di.GetFileSystemInfos( "*.*", SearchOption.AllDirectories );
        // fsi = di.GetFileSystemInfos( "*", SearchOption.AllDirectories );

    AllDirectories mean includes the current directory and all its subdirectories in a search operation. This option includes reparse points such as mounted drives and symbolic links in the search. Not all the directories will allow to you access. It is more related to permissions.

    TopDirectoryOnly mesn it includes only the current directory in a search operation. It is a default value of this parameter. Hence it is easily to succeed.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by User3DX Thursday, October 26, 2017 8:44 AM
    Thursday, October 26, 2017 6:36 AM
    Moderator
  • Hello,

     Thanks for reply. I kinda thought it would something with nested folder access

    but could not get a complete answer from Microsoft class documentation.

     

    Thanks :)

    Thursday, October 26, 2017 8:46 AM