3 Replies - 1054 Views - Last Post: 13 July 2011 - 06:24 AM Rate Topic: -----

#1 chls89  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 47
  • Joined: 19-September 09

File copy app - massive num of directories

Posted 12 July 2011 - 03:15 PM

I'm beginning work on a simple .NET Windows application. This is a utility that will be used to copy a massive number of image files from one server to another. This is required as we will do some 'smart' copying (some files will need copying, certain ones won't - irrelevant to this question). The issue with this application is that not only are both servers obviously remote, slowing everything down, but the number of directories under the handful of root directories is pretty massive - nearly 400K directories in cases. From some preliminary development, I have noticed that, for example, the call to the GetDirectories() function:

For Each diInventory as DirectoryInfo in diRoot.GetDirectories()  'diRoot is a directory containing 400K files, e.g.



takes an excessively long amount of time - this is just the enumeration of the directories obviously, so by the time file copies are done for each, we're talking about an unacceptable amount of time that this application will have to run. Any tips on this or in general about this sort of application? Is there a more efficient way of enumerating directories or files within directories? I've noticed that Windows 7 cannot handle opening one of these directories with hundreds of thousands of files - Windows itself locks up. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: File copy app - massive num of directories

#2 Alexanderj  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 13
  • Joined: 07-July 11

Re: File copy app - massive num of directories

Posted 12 July 2011 - 03:33 PM

did you try the folowing code ?

 
   Dim dirs As List(Of String) = Directory.EnumerateDirectories("c:/").ToList()

        For Each dir As String In dirs
            ListBox1.Items.Add(dir)

        Next


Was This Post Helpful? 1
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

Re: File copy app - massive num of directories

Posted 12 July 2011 - 08:06 PM

You need to use threading for this. You will need to know how to use delegates you need to access the form or any controls from the other threads. More specifically using the Threadpool.

This post has been edited by hawkvalley1: 12 July 2011 - 08:16 PM

Was This Post Helpful? 1
  • +
  • -

#4 chls89  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 47
  • Joined: 19-September 09

Re: File copy app - massive num of directories

Posted 13 July 2011 - 06:24 AM

Aha! Thanks @hawkvalley1 - I was naturally thinking about using the threading libraries, but any info helps so I'll look into Threadpool. @Alexanderj - Score! I made a mistake and learned a good lesson here - IntelliSense should be a tool and not be heavily relied on. I work with a pretty large code base and we develop in .NET 2.0 (for web apps). But switching to a later version for this app which will run locally allowed me to use the 'newer' Directory.EnumerateXXX methods. I should have looked at the reference for Directory rather than use IntelliSense tell me what is available. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1