c# - .net File.Copy very slow when copying many small files (not over network) -


i'm making simple folder sync backup tool myself , ran quite roadblock using file.copy. doing tests copying folder of ~44,000 small files (windows mail folders) drive in system, found using file.copy on 3x slower using command line , running xcopy copy same files/folders. c# version takes on 16+ minutes copy files, whereas xcopy takes 5 minutes. i've tried searching on topic, find people complaining slow file copying of large files on network. neither large file problem nor network copying problem.

i found interesting article better file.copy replacement, code posted has errors causes problems stack , near knowledgeable enough fix problems in code.

are there common or easy ways replace file.copy more speedy?

one thing consider whether copy has user interface updates during copy. if so, make sure copy running on separate thread, or both ui freeze during copy, , copy slowed down making blocking calls update ui.

i have written similar program , in experience, code ran faster windows explorer copy (not sure xcopy command prompt).

also if have ui, don't update on every file; instead update every x megabytes or every y files (whichever comes first), keeps down amount of updating ui can handle. used every .5mb or 10 files; may not optimal noticeably increased copy speed , ui responsiveness.

another way speed things use enumerate functions instead of functions (e.g. enumeratefiles instead of getfiles). these functions start returning results possible instead of waiting return when list finished being built. return enumerable, can call foreach on result: foreach(string file in system.io.directory.enumeratedirectories(path)). program made noticeable difference in speed, , more helpful in cases yours dealing directories containing many files.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -