none
Exception Details: System.IO.IOException: There are no more files.

    Question

  •  

    Hi,

         I have a problem in accessing files in a folder. My code is as follows

     

    Code Snippet

    String[] files = Directory.GetFiles("c:\\myfolder","abc*.exe", SearchOption.AllDirectories);

     

     

     

    When i give the path as "c:\\myfolder", it retrieves all the exe files starting with abc in that folder or in the subfolders.

     

    But when I share the folder with all rights set, it gives me an error

     

    There are no more files.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.IO.IOException: There are no more files.

    ..................

     

    The code that gave the error is

     

     

    Code Snippet

    String[] files = Directory.GetFiles("\\\\localhost\\myfolder","abc*.exe", SearchOption.AllDirectories);

     

     

     

    Can someone help me out.

     

    Friday, February 22, 2008 12:25 PM

Answers

  • Subramanian.SS,

     

    Based on your post, I tested the Directory.GetFiles method on my local machine with the following code snippet:

     

    Code Snippet

            Dim files As String() = Directory.GetFiles("\\localhost\Generator", "*.sln", SearchOption.AllDirectories)

            For Each s In files

                Console.WriteLine(s)

            Next

            Console.ReadLine()

     

     

    You can easily convert the VB.NET code in C# since I am more familiar with the VB.NET. I can get the correct result in my Generator shared folder with all the .sln files.

     

    I am using Windows Server 2003 with the Administrator account, VB 2008 Express Edition.

     

    Except the Directory.GetFiles, you can try to use DirectoryInfo.GetFiles method instead. For further information and the code example, please visit the link below:

     

    http://msdn2.microsoft.com/en-us/library/4cyf24ss.aspx 

     

    You can also take a look at the thread Problem with System.IO.Directory.GetFiles with the similar problem.

     

    Hope that can help you.

    Tuesday, February 26, 2008 6:30 AM

All replies

  • Is this code running on an external machine?  If so, you need to make sure your path is to a public folder, so not "localhost".  You also need to make sure that the permissions on the folder and files allow the users to view the share and the directory.
    Friday, February 22, 2008 12:50 PM
  • I have not yet tested it on an external machine

     

    I've given all the rights to the folder.

    This code actually works..

     

     

    Code Snippet

    String [] files=Directory.GetFiles("\\\\localhost\\myfolder","abc1.exe",SearchOption.AllDirectories);

     

     

     

    but

     

    Code Snippet
    String [] files=Directory.GetFiles("\\\\localhost\\myfolder","abc*.exe",SearchOption.AllDirectories);

     

     

     

    doesn't work.

     

     

    Friday, February 22, 2008 2:38 PM
  • Subramanian.SS,

     

    Based on your post, I tested the Directory.GetFiles method on my local machine with the following code snippet:

     

    Code Snippet

            Dim files As String() = Directory.GetFiles("\\localhost\Generator", "*.sln", SearchOption.AllDirectories)

            For Each s In files

                Console.WriteLine(s)

            Next

            Console.ReadLine()

     

     

    You can easily convert the VB.NET code in C# since I am more familiar with the VB.NET. I can get the correct result in my Generator shared folder with all the .sln files.

     

    I am using Windows Server 2003 with the Administrator account, VB 2008 Express Edition.

     

    Except the Directory.GetFiles, you can try to use DirectoryInfo.GetFiles method instead. For further information and the code example, please visit the link below:

     

    http://msdn2.microsoft.com/en-us/library/4cyf24ss.aspx 

     

    You can also take a look at the thread Problem with System.IO.Directory.GetFiles with the similar problem.

     

    Hope that can help you.

    Tuesday, February 26, 2008 6:30 AM
  • I'm getting the same problem when trying to use GetFiles if there are no matches to the search on a network share; it works fine on local drives:

    System.IO.IOException: There are no more files.
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, ...
                  Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
       at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)

    The MSDN documentation doesn't mention this possibility for the Directory.GetFiles method, and the expected behaviour should be that an empty array is returned if no files are found (which is what happens on local drives). Therefore, this definitely seems like a bug in the .NET Framework -- is this the right place to report it?

    I'd say the Framework should be catching this exception internally in Directory.GetFiles and returning an empty array instead.
    Wednesday, August 06, 2008 9:15 PM
  • I am getting the same error.  What is the status of this?  Is there a workaround?
    Thursday, January 22, 2009 12:00 AM
  • Are you using virtualbox? I saw reports of similar problems from people running XP as a guest under virtualbox, with various unixes as a host.
    Friday, August 07, 2009 2:25 PM