Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Как копировать папку c СD-Rom на С


Автор: Serhik_z 27.4.2006, 16:05
Как копировать папку с ее содержимым папками и файлами, с диска CD-Rom на диск С:/, если 
приводов CD-Rom несколько, а диск СD находится в одном из приводов.

Код

function GetCDRoms: string; // Возвращает строку - список CD-ROM'ов
var
  d: dword;
  b: byte;
begin
  result := '';
  d := GetLogicalDrives;
  for b := 0 to 31 do
    if d and (1 shl b) > 0 then
      if GetDriveType(PChar(chr(b+65)+':\')) = DRIVE_CDROM then
        result := result + chr(b+65);
end;

function GetCDExist: string; // Возвращает список CD-ROM в которых есть диск
var
  i: integer;
  buf: array[0..MAX_PATH] of char;
  d:  dword;
begin
  result := GetCDRoms;
  SetErrorMode(SEM_FAILCRITICALERRORS);
  for i := Length(result) downto 1 do
    if not GetVolumeInformation(PChar(result[i] + ':\'), @buf, MAX_PATH,
                                nil, d, d, @buf, MAX_PATH) then
      Delete(result, i, 1);
end;


 smile  smile  smile 
 

Автор: Alexeis 27.4.2006, 16:19
Вот пример из delphiWorld
Код

function FullDirectoryCopy(SourceDir, TargetDir: string; StopIfNotAllCopied,
  OverWriteFiles: Boolean): Boolean;
var
  SR: TSearchRec;
  I: Integer;
begin
  Result := False;
  SourceDir := IncludeTrailingBackslash(SourceDir);
  TargetDir := IncludeTrailingBackslash(TargetDir);
  if not DirectoryExists(SourceDir) then
    Exit;
  if not ForceDirectories(TargetDir) then
    Exit;

  I := FindFirst(SourceDir + '*', faAnyFile, SR);
  try
    while I = 0 do
    begin
      if (SR.Name <> '') and (SR.Name <> '.') and (SR.Name <> '..') then
      begin
        if SR.Attr = faDirectory then
          Result := FullDirectoryCopy(SourceDir + SR.Name, TargetDir + SR.NAME,
            StopIfNotAllCopied, OverWriteFiles)
        else if not (not OverWriteFiles and FileExists(TargetDir + SR.Name))
          then
          Result := CopyFile(Pchar(SourceDir + SR.Name), Pchar(TargetDir +
            SR.Name), False)
        else
          Result := True;
        if not Result and StopIfNotAllCopied then
          exit;
      end;
      I := FindNext(SR);
    end;
  finally
    SysUtils.FindClose(SR);
  end;
end;
Пример использования: 

FullDirectoryCopy('C:\a', 'D:\b');

 

Автор: Snowy 27.4.2006, 16:26
http://forum.vingrad.ru/index.php?showtopic=87911  

Автор: Alexeis 27.4.2006, 16:30
Snowy, так это же его и была тема, решение этого вопроса он не просит, поскольку сам привел(вторая процедура).
Вопрос как я понял в копировании smile  

Автор: Snowy 27.4.2006, 16:32
Берем этот код: http://forum.vingrad.ru/index.php?showtopic=87911&view=findpost&p=675167
И код http://forum.vingrad.ru/index.php?showtopic=93669&view=findpost&p=714383
Используем:
Код
var    
  i: integer;    
  s: string;    
begin    
  s := GetCDExist;    
  for i := 1 to Length(s) do    
    FullDirectoryCopy(s[i] + ':\', 'C:\CD_'+ s[i] + '-COPY\');
end;
  

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)