Re: Large directories... DirectoryInfo or Win32 API?

From: Robert Jordan (robertj_at_gmx.net)
Date: 10/01/04


Date: Fri, 01 Oct 2004 14:04:23 +0200

Justin Rogers wrote:

> Internally they are doing the Win32 API calls for you. However, they are
> also allocating a LOT of array space to do it. Specifically they are making
> an extra copy, which probably isn't necessary, and there is a possible
> resource leak in that particular method that they aren't accounting for.

Really weird is the fact that Directory.GetFiles returns a string array
with fully qualified file names. Imagine you want to enumerate

c:\documents and settings\
   \SomeUsername
     \Program Data
       \some scary long company name
         \even longer fancy product name

or some huge UNC path hierarchies

\\server\share\public\org\unit\projekt\subproject\trash\

DirectoryInfo.GetFiles returns an array of FileInfo which
is probably even larger then the fully qualified file name.

I wonder why MS didn't desiged that API to return an object
"FileList", whose enumerator calls Win32's FindNextFile
just in time (or on demand).

bye
Rob



Relevant Pages

  • Re: For Each
    ... For Each will enumerate the collection from lowest to highest index ... A For loop to enumerate an array will be ... Unless you are the controlling process, ...
    (microsoft.public.scripting.vbscript)
  • Re: Combinations problem
    ... the array then walk it and collapse it down to one instance ... That should ring ... Thus all you have to do is enumerate ...
    (comp.lang.c)
  • Re: Permission Denied when using File.Copy or fso.CopyFile
    ... you need to enumerate all your files and copy them one ... otherwise (i.e. if you copy a folder) you cannot say what file ... filename to an array for later retry. ... window while user are browsing). ...
    (microsoft.public.scripting.vbscript)
  • Re: AD Group members without knowing full DN
    ... recursively enumerate all GROUPS within AD and load the DN into an array ... >> for a script to list group membership.... ... > An example on a script using NameTranslate: ...
    (microsoft.public.scripting.vbscript)
  • RE: Foreach Loop Container - Filter for Multiple Files.
    ... One way of sorting this problem would to to store the names of the files in a variable (array) You could then enumerate the variable then in the ForEach Loop enumerator. ...
    (microsoft.public.sqlserver.dts)