FindFirstでファイルのコピー

解決


studio-take  2012-08-14 16:40:37  No: 42767  IP: 192.*.*.*

作成したアプリをいちいちみんなのPCに設定するのが面倒なので、サーバーに置いて、読みに行くソースをメインのEXEファイルに入れたのですが、
DLLとフォルダをコピーしたいんですけど、
ボリュームファイルとかまでついてきているみたいなので、困っています。
できれば、EXEファイルが入っていても排除するソースにしたいのですが。

var
  osr,nsr:TSearchRec;
  cnt:Integer;
  oft,nft:TFileTime;
  ost,nst:TSystemTime;
  nd,od:TDateTime;
  AppPath:String;
  FromPath,ToPath : String;
  LCID:Windows.LCID;
  FileOp:TShFileOpStruct;
  FileAttrs: Integer;

begin
  AppPath := ExtractFilePath(Application.ExeName);
  FileAttrs := FaDirectory + FaReadOnly;
  //DLLのコピー
  if FindFirst(UpdatePath + '\*.*',FileAttrs,nsr) = 0 then
  begin
    Repeat
      //共有ファイル先のファイルの日付取得
      FileTimeToLocalFileTime(nsr.FindData.ftLastWriteTime,nft);
      FileTimeToSystemTime(nft,nst);
      nd := SystemTimeToDateTime(nst);
      //同じファイル名の既存日付取得
      FindFirst(AppPath + nsr.Name,FaAnyFile,osr);
      FileTimeToLocalFileTime(osr.FindData.ftLastWriteTime,oft);
      FileTimeToSystemTime(oft,ost);
      od := SystemTimeToDateTime(ost);
      //確認
      ShowMessage(nsr.Name + ' : '+ DateTimeToStr(od) + ' : ' + DateTimeToStr(nd));
    //もし新しかったらコピー
    if od < nd then
    begin
      //ファイル原本コピー
      FromPath := UpDatePath + '\' + nsr.Name + #0#0;
      ToPath   := AppPath + nsr.Name + #0#0;
      with FileOp do
      begin
        Wnd    := frmMain.Handle;
        wFunc  := FO_COPY;
        pFrom  := PChar(FromPath);
        pTo    := PChar(ToPath);
        fFlags := FOF_NOCONFIRMATION;//上書き問い合わせ無し
      end;
      SHFileOperation(FileOp);
    end;

    until FindNext(nsr) <> 0;
    FindClose(nsr);
    FindClose(osr);
  end;
end;

編集 削除
studio-take  2012-08-14 16:48:13  No: 42768  IP: 192.*.*.*

cnt:integer;//ゴミ宣言です。

updatePath//サーバーのパスが入ってます。

FindFirst(UpdatePath + '\*.*',FileAttrs,nsr) 

の'\*.*'を'\*.dll'にしたらDLLだけはとれたんですが、
フォルダのみの取り方が分からず、戻しました。

最悪、DLLのみ回すのと、フォルダのみ回して読むのでもかまわないです。

編集 削除
 2012-08-14 18:45:54  No: 42769  IP: 192.*.*.*

DirectoryExistsでふるいにかければ簡単では?
あるいは、faDirectoryで検索してみると、それらしいソースが拾えるかも。

編集 削除
studio-take  2012-08-14 20:44:35  No: 42770  IP: 192.*.*.*

あ、さんヒントありがとうございました。
いいソースがありました。

if (nsr.Name <> '.') and (nsr.Name <> '..') then
begin

end;
で囲むとうまくいきました。

編集 削除