Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Move files is too slow

Posted on 2006-04-03
Medium Priority
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?

imports system.io

    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
  • 2

Author Comment

ID: 16365516
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

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

Thanks anyway!

Expert Comment

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

Accepted Solution

gregoryyoung earned 2000 total points
ID: 16368526
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)



Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

571 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