Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 23.12.2008, 15:05   #1
Demien
Форумчанин
 
Аватар для Demien
 
Регистрация: 01.08.2007
Сообщений: 222
Печаль Копирование файлов

Пишу программу для копирования файлов.
Условия: Постоянное сканирование папки-источника и при появлении нового\новых файла копирование его в другую папку.
Допустим сканирование можно пустить через TTimer. С этим проблемм нет! Сама процедура сканирования у меня тоже рабочая!
Проблемма заключается в самом копировании файлов...
Как скопировать несколько файлов поочередно, сохраняя их имена и при этом не копировать уже скопированные.....
Привожу пример имен файлов:
20081202_1_2013_081208063337
20081202_1_2023_081208063330
20081202_1_2040_081208063319
Расширение: ".upfarc" (в принципе не существенно...)
Имена файлов не имеют и какой логичаской последовательности...
Как быть?
Жить тоже вредно, от этого умирают!!!
Demien вне форума Ответить с цитированием
Старый 23.12.2008, 15:15   #2
Квэнди
Старожил
 
Аватар для Квэнди
 
Регистрация: 13.12.2006
Сообщений: 3,859
По умолчанию

copyfile +f1
ICQ не для вопросов, а для предложений. Для вопросов используйте форум
IRC канал клуба программистов|Мои статьи
Квэнди вне форума Ответить с цитированием
Старый 23.12.2008, 15:30   #3
Demien
Форумчанин
 
Аватар для Demien
 
Регистрация: 01.08.2007
Сообщений: 222
По умолчанию

Цитата:
Сообщение от Квэнди Посмотреть сообщение
copyfile +f1
Я в программировании не профи...
...только учусь.
Можно подробней?
Жить тоже вредно, от этого умирают!!!
Demien вне форума Ответить с цитированием
Старый 23.12.2008, 15:37   #4
Квэнди
Старожил
 
Аватар для Квэнди
 
Регистрация: 13.12.2006
Сообщений: 3,859
По умолчанию

Цитата:
CopyFile

The CopyFile function copies an existing file to a new file.

The CopyFileEx function provides two additional capabilities. CopyFileEx can call a specified callback function each time a portion of the copy operation is completed, and CopyFileEx can be canceled during the copy operation.


BOOL CopyFile(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName,
BOOL bFailIfExists
);

Parameters
lpExistingFileName
[in] Pointer to a null-terminated string that specifies the name of an existing file.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
If lpExistingFileName does not exist, CopyFile fails, and GetLastError returns ERROR_FILE_NOT_FOUND.

lpNewFileName
[in] Pointer to a null-terminated string that specifies the name of the new file.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
bFailIfExists
[in] If this parameter is TRUE and the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Security attributes for the existing file are not copied to the new file. To copy security attributes, use the SHFileOperation function.

File attributes for the existing file are copied to the new file. For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute. For more information, see Retrieving and Changing File Attributes.

This function fails with ERROR_ACCESS_DENIED if the destination file already exists and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.


When CopyFile is used to copy an encrypted file, it attempts to encrypt the destination file with the keys used in the encryption of the source file. If this cannot be done, this function attempts to encrypt the destination file with default keys, as in Windows 2000. If neither of these methods can be done, CopyFile fails with an ERROR_ENCRYPTION_FAILED error code.

Windows 2000: When CopyFile is used to copy an encrypted file, the function attempts to encrypt the destination file with the default keys. No attempt is made to encrypt the destination file with the keys used in the encryption of the source file. If it cannot be encrypted, CopyFile completes the copy operation without encrypting the destination file.



Symbolic link behavior—If the source file is a symbolic link, the actual file copied is the target of the symbolic link.

If the destination file already exists and is a symbolic link, the symbolic link is overwritten by the source file.


Example Code
For an example, see Retrieving and Changing File Attributes.

Requirements
Client Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header Declared in Winbase.h; include Windows.h.

Library Use Kernel32.lib.

DLL Requires Kernel32.dll.
Unicode Implemented as CopyFileW (Unicode) and CopyFileA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
куда уже еще подробней
Тем более если вы только начинаете, то учиться пользоваться справкой надо тем более.
ICQ не для вопросов, а для предложений. Для вопросов используйте форум
IRC канал клуба программистов|Мои статьи
Квэнди вне форума Ответить с цитированием
Старый 23.12.2008, 16:20   #5
Altera
Старожил
 
Аватар для Altera
 
Регистрация: 29.01.2008
Сообщений: 2,406
По умолчанию

Он не понял надпись copyfile +f1.
Demien, Квэнди хотел этим сказать, что надо выделить функцию copyfile в редакторе делфи и нажать F1. При этом вылезает справка по функции.
Altera вне форума Ответить с цитированием
Старый 23.12.2008, 16:23   #6
KORN
Банхаммер
Участник клуба
 
Аватар для KORN
 
Регистрация: 17.02.2007
Сообщений: 1,754
По умолчанию

if copyfile(pchar(имя файла), Pchar(новое местоположение), true) then
// файл скопирован
else
// файл не скопирован
Перед тем как спросить ищи на форуме и в GOOGLE
KORN вне форума Ответить с цитированием
Старый 25.03.2010, 14:10   #7
Jack_Inc
 
Регистрация: 04.09.2009
Сообщений: 4
По умолчанию

Цитата:
Сообщение от Demien Посмотреть сообщение
Пишу программу для копирования файлов.
Условия: Постоянное сканирование папки-источника и при появлении нового\новых файла копирование его в другую папку.
Допустим сканирование можно пустить через TTimer. С этим проблемм нет! Сама процедура сканирования у меня тоже рабочая!
Проблемма заключается в самом копировании файлов...
Как скопировать несколько файлов поочередно, сохраняя их имена и при этом не копировать уже скопированные.....
Привожу пример имен файлов:
20081202_1_2013_081208063337
20081202_1_2023_081208063330
20081202_1_2040_081208063319
Расширение: ".upfarc" (в принципе не существенно...)
Имена файлов не имеют и какой логичаской последовательности...
Как быть?
Слушай а у тебя проги случайно не осталось этой, а то у меня такая же задача сейчас стоит.
Jack_Inc вне форума Ответить с цитированием
Старый 25.03.2010, 15:29   #8
bitSoft
Programming...
Форумчанин
 
Аватар для bitSoft
 
Регистрация: 13.03.2010
Сообщений: 198
По умолчанию

Код:
if not FileExists(blablabla) then CopyFile(blablabla);
Код:
With TProgrammersForum.Create do  AddNewTopic('Title','Content...');
bitSoft вне форума Ответить с цитированием
Старый 25.03.2010, 16:05   #9
FaTaL
Участник клуба
 
Аватар для FaTaL
 
Регистрация: 09.11.2007
Сообщений: 1,762
По умолчанию

Задача простая. Как то делал что-то подобное, но исходник дома. Если очень нужно, то стучи в аську на аватаре. Прям весь исходник скину или даже напишу сейчас пока есть время.

Вот наваял на скорую руку, если что не понятно, то пиши:
Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    procedure SearchAndCopy (SFolder, DFolder : WideString);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



{ TForm1 }

procedure TForm1.SearchAndCopy(SFolder, DFolder: WideString);
var
SR:TSearchRec;
FindRes:Integer;
N:String;
begin
findRes:=FindFirst(SFolder + '*.*', faAnyFile, SR);
  while findres = 0 do
    begin
    N:=SR.Name;
    if not FileExists (DFolder + N) then
      CopyFile (PChar (SFolder + N), PChar (DFolder + N), false);
    FindRes:=FindNext(SR);
    end;
    FindClose (SR);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  SearchAndCopy ('Папка где искать', 'Папка куда копировать');
  // Пути должны к папкам заканчиваться обязательно знаком "\"
end;

end.

Последний раз редактировалось FaTaL; 25.03.2010 в 16:24.
FaTaL вне форума Ответить с цитированием
Старый 26.03.2010, 08:52   #10
Jack_Inc
 
Регистрация: 04.09.2009
Сообщений: 4
По умолчанию

Спаисбо
Jack_Inc вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Копирование файлов Artificial Помощь студентам 5 05.06.2008 18:42
Копирование файлов matus Помощь студентам 9 27.02.2008 19:34
копирование файлов matus Общие вопросы Delphi 2 07.11.2007 21:57
Копирование файлов Devil_uu Помощь студентам 2 24.03.2007 20:27