Posts tagged: File Copy

Copying Large Files

By Ashish Khandelwal, September 10, 2009

Windows Server 2008 provides at least three different command line utilities for copying files. The familiar COPY and XCOPY commands have been around since the early DOS days. And ROBOCOPY, a more robust and feature-rich tool, began shipping with Windows Vista and Windows Server 2008. These tools work just fine in most cases. But all three suffer from a fatal flaw when you’re trying to copy a file that’s larger than available memory.

Manifestation of the Problem

Our main servers are quad-core machines with 32 gigabytes of RAM, running the 64 bit version of Windows Server 2008. Our custom format repository file is about 90 gigabytes in size. That’s after compression. In addition to daily backups, I periodically need to copy that file to another computer. And that’s where the problems start. Read more »

VN:F [1.7.2_963]
Rating: 2.7/5 (3 votes cast)

Replacing File.Copy

By Ashish Khandelwal, September 10, 2009

The easiest way to copy a file in a .NET program is to call the File.Copy method, supplying it the source and destination files. It could hardly be simpler than this:

File.Copy(srcFilename, destFilename);

That method will throw IOException if there is an existing file of the same name as destFilename. If you want to overwrite existing files, call the overload and specify true for the overwrite parameter:

File.Copy(srcFilename, destFilename, true);

File.Copy certainly is very easy to use, but as I mentioned in the previous section, it suffers from the large file copy problem. That is, using File.Copy to copy a very large file from one machine to another can cause the source machine to run out of memory. For example, I encountered that problem when executing a statement of this form:

File.Copy(@"\\server\data\file.dat", @"d:\data\file.dat", true);

If you want to copy a file and not encounter those problems, you have to write your own copy method. Read more »

VN:F [1.7.2_963]
Rating: 4.0/5 (1 vote cast)