Move files is too slow

Posted on 2006-04-03
Last Modified: 2010-04-23
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
Question by:xfungalx

    Author Comment

    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...

    Author Comment

    Got it, put the folder size checker on a seperate timer and out of the loop.  Problem resolved.

    Thanks anyway!
    LVL 9

    Expert Comment

    by:Naveen Swamy
    and don't forget to use System.Windows.Forms.Application.DoEvents()
    LVL 37

    Accepted Solution

    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)



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now