Move files is too slow

Hi experts

I am using the following routine to move files one by one.  The idea is to split a large directory (over 600MB) that is full of small .dat files into smaller directories to facilitate burning them to CD's.  It worked great during testing when I was using 6 MB chunks, however I want to finish up the app now, so I moved it to the final size of appx 600 MB and it is taking way too long!  How can I make this FASTER?  Am I up a river here?


    Public Shared Sub MoveFiles(ByVal Path As String, ByVal Dest As String)
        Dim aFiles() As String = Directory.GetFiles(Path)
        Dim s As String
            For Each s In aFiles
                If GetFolderSizeMB(Dest) < 597 Then 'Check how big the destination folder is getting and make a desicision based on that
                    File.Move(s, s.Replace(Path, Dest)) 'replace pathnames
                    My.Computer.FileSystem.WriteAllText(Dest & "\marker.txt", "marker", True) 'Create a file in each directory.  A timer running in this particular application checks for this file so as to know when to change to the next step.
                End If
            Next s
        End Try
    End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xfungalxAuthor Commented:
Simply writing the question here allows me to see the HUGE bottleneck here.  Getting the folder size on every pass of the loop is what is KILLING me here.  I will recode this and see if I can find a better way to track the size...
xfungalxAuthor Commented:
Got it, put the folder size checker on a seperate timer and out of the loop.  Problem resolved.

Thanks anyway!
Naveen SwamyYash Infinite Solutions Private LimitedCommented:
and don't forget to use System.Windows.Forms.Application.DoEvents()
here's an easier thought ..

instead of checking how big it has gotten by iterating all the folders every time ... just remember (and add together) the sizes of all of the files you are copying over ... this should make it so you only need to caluclate the existing size once (then just add the amount you have copied to the original size). This would also allow it to be deterministic where as the timer is not deterministic (you could get into a funny situation where the timer doesn't get a chance to run but the data is too big (if someone were quick)



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.