Comments on: C# Alternative to Directory.GetFiles() http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/ Stuff Ron Gross Finds Interesting Sun, 02 Aug 2015 11:03:35 +0000 hourly 1 https://wordpress.org/?v=4.5.3 By: Desarrollador http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1994 Fri, 22 Jan 2010 22:08:57 +0000 http://v1.ripper234.com/?p=937#comment-1994 Very interesting, very functional
I congratulate them.

My aplications daily process 6000 files. I integrate this code. Thanks

]]>
By: ripper234 http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1591 Mon, 24 Aug 2009 06:05:17 +0000 http://v1.ripper234.com/?p=937#comment-1591 You can try having the enumerator close itself automatically at the end of iteration:

if (lastError == ERROR_NO_MORE_FILES)
{
// try calling Reset(); or Dispose(); here
return false;
}

]]>
By: tjam http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1590 Sun, 23 Aug 2009 22:07:31 +0000 http://v1.ripper234.com/?p=937#comment-1590 Hmmm. I must not be getting this. I changed the class FilesFinder so I could call the Dispose()method on the enumerator:

public class FilesFinder : IEnumerable
{
readonly string _fileName;
IEnumerator _fileenumerator;

public FilesFinder(string fileName)
{
_fileName = fileName;
_fileenumerator = new FilesEnumerator(_fileName);
}

public IEnumerator GetEnumerator()
{
return _fileenumerator;
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public void Dispose()
{
_fileenumerator.Dispose();
}

}

Then added: filesFinder.Dispose(); the GetFiles()method after the foreach completed.

Still no luck.

]]>
By: ripper234 http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1584 Fri, 21 Aug 2009 16:36:13 +0000 http://v1.ripper234.com/?p=937#comment-1584 Amm … after you’re finished using FilesEnumerator? It holds the directory open.

]]>
By: tjam http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1582 Fri, 21 Aug 2009 14:15:33 +0000 http://v1.ripper234.com/?p=937#comment-1582 I have to admit my ignorance here. No, I am not calling Dsipose. But I’m not exactly sure where to call it.

]]>
By: ripper234 http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1578 Fri, 21 Aug 2009 06:41:19 +0000 http://v1.ripper234.com/?p=937#comment-1578 @tijam, note that FilesEnumerator has a Dispose method (even though my implementation didn’t implement the IDisposable pattern – it rather should). Are you calling Dispose()?4

]]>
By: tjam http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1577 Thu, 20 Aug 2009 21:43:21 +0000 http://v1.ripper234.com/?p=937#comment-1577 I’m using this code to grab “handfuls” of files and move them to a different directory. It works great, except when the original directory is empty, I want to delete it. Unfortunately, any attempt I make results in an error indicating the directory is being used by another process, the culprit seeming to be your GetFiles. When using the Directory.GetFiles() I am able to process everything and perform the delete. But I really need to use your method for grabbing smaller chunks. It works perfectly except for not wanting to release the directory. Any ideas?

]]>
By: ripper234 http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1509 Tue, 14 Jul 2009 14:14:18 +0000 http://v1.ripper234.com/?p=937#comment-1509 FindFirstFile does no sorting of the search result (MSDN)

]]>
By: slide http://v1.ripper234.com/p/c-alternative-to-directorygetfiles/comment-page-1/#comment-1508 Tue, 14 Jul 2009 13:35:57 +0000 http://v1.ripper234.com/?p=937#comment-1508 I’m very interested in this code, had one question though. Does it return the files in sorted order?

]]>