델파이

웹에 있는 파일 다운로드 받기(UrlDownloadToFile)

유돌이 2008. 12. 24. 17:59

//[함수 구현 부분]

 

function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
  try
  Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
  except
  Result := False;
  end;
end;

// [함수 호출 부분~]

 

// 다운로드할 URL 경로
SourceFile = 'http://.../SB_DB.txt';
// 저장할 파일의 경로
DestFile = 'c:\SB_DB.txt';

if DownloadFile(SourceFile, DestFile) then begin
    ShowMessage('Download succesful!');
    ShellExecute(Application.Handle, PChar('open'), PChar(DestFile),
    PChar(''), nil, SW_NORMAL)
  end else begin
    ShowMessage('Error while downloading ' + SourceFile)
  end;