CopyFile 또는 CopyFileEx 없이 Windows에서 대용량 파일을 어떻게 복사할 수 있나요?

StackOverflow https://stackoverflow.com/questions/92114

  •  01-07-2019
  •  | 
  •  

문제

Windows Server 2003에는 RAM 용량에 비례하여 매우 큰 파일을 복사할 수 없다는 제한 사항이 있습니다.제한 사항은 xcopy, Explorer, Robocopy 및 .NET FileInfo 클래스에서 사용되는 CopyFile 및 CopyFileEx 함수에 있습니다.

다음과 같은 오류가 발생합니다.

[파일 이름]을(를) 복사할 수 없습니다:요청한 서비스를 완료하기에는 시스템 리소스가 부족합니다.

지식 기반 기사 주제에 대해서는 NT4 및 2000과 관련이 있습니다.

에 대한 제안도 있습니다. ESEUTIL을 사용하세요 Exchange를 설치했지만 제대로 작동하지 못했습니다.

이 문제를 처리하는 빠르고 쉬운 방법을 아는 사람이 있습니까?RAM이 2GB인 시스템에서는 50GB가 넘는다는 의미입니다.나는 Visual Studio를 실행하고 나를 위해 뭔가를 작성할 계획이지만 이미 안정적이고 잘 테스트된 것이 있으면 좋을 것입니다.

[편집하다] 허용되는 답변과 함께 작동하는 C# 코드를 제공했습니다.

도움이 되었습니까?

해결책

가장 좋은 방법은 읽기 위해 원본 파일을 열고 쓰기 위해 대상 파일을 연 다음 블록 단위로 반복 복사하는 것입니다.의사 코드에서 :

f1 = open(filename1);
f2 = open(filename2, "w");
while( !f1.eof() ) {
  buffer = f1.read(buffersize);
  err = f2.write(buffer, buffersize);
  if err != NO_ERROR_CODE
    break;
}
f1.close(); f2.close();

[Asker 편집] 좋습니다. C#에서는 다음과 같습니다(느리지만 제대로 작동하는 것 같고 진행이 진행됩니다).

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace LoopCopy
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine(
                  "Usage: LoopCopy.exe SourceFile DestFile");
                return;
            }

            string srcName = args[0];
            string destName = args[1];

            FileInfo sourceFile = new FileInfo(srcName);
            if (!sourceFile.Exists)
            {
                Console.WriteLine("Source file {0} does not exist", 
                    srcName);
                return;
            }
            long fileLen = sourceFile.Length;

            FileInfo destFile = new FileInfo(destName);
            if (destFile.Exists)
            {
                Console.WriteLine("Destination file {0} already exists", 
                    destName);
                return;
            }

            int buflen = 1024;
            byte[] buf = new byte[buflen];
            long totalBytesRead = 0;
            double pctDone = 0;
            string msg = "";
            int numReads = 0;
            Console.Write("Progress: ");
            using (FileStream sourceStream = 
              new FileStream(srcName, FileMode.Open))
            {
                using (FileStream destStream = 
                    new FileStream(destName, FileMode.CreateNew))
                {
                    while (true)
                    {
                        numReads++;
                        int bytesRead = sourceStream.Read(buf, 0, buflen);
                        if (bytesRead == 0) break; 
                        destStream.Write(buf, 0, bytesRead);

                        totalBytesRead += bytesRead;
                        if (numReads % 10 == 0)
                        {
                            for (int i = 0; i < msg.Length; i++)
                            {
                                Console.Write("\b \b");
                            }
                            pctDone = (double)
                                ((double)totalBytesRead / (double)fileLen);
                            msg = string.Format("{0}%", 
                                     (int)(pctDone * 100));
                            Console.Write(msg);
                        }

                        if (bytesRead < buflen) break;

                    }
                }
            }

            for (int i = 0; i < msg.Length; i++)
            {
                Console.Write("\b \b");
            }
            Console.WriteLine("100%");
            Console.WriteLine("Done");
        }
    }
}

다른 팁

코드를 작성하려는 경우 최적화할 수 있는 한 가지 방법은 파일을 청크로 보내는 것입니다(예: 엠톰).저는 인쇄를 위해 DataCenter에서 사무실로 대용량 파일을 보내는 데 이 접근 방식을 사용했습니다.

또한 언급된 TeraCopy 유틸리티를 확인하세요. 여기..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top