AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi "SHFileOperation" beschwert sich bei geöffneten Dateien
Thema durchsuchen
Ansicht
Themen-Optionen

"SHFileOperation" beschwert sich bei geöffneten Dateien

Ein Thema von irata · begonnen am 5. Okt 2006 · letzter Beitrag vom 5. Okt 2006
Antwort Antwort
irata

Registriert seit: 5. Okt 2006
4 Beiträge
 
#1

Re: "SHFileOperation" beschwert sich bei geöffnete

  Alt 5. Okt 2006, 09:38
Hallo,

hier die "Move" Routine:
Delphi-Quellcode:
function TFmMain.MoveFile(const AOldName, ANewName: string ): boolean;
var
  sh: TSHFileOpStruct;
begin
  try
    FillChar(sh, sizeOf(TSHFileOpStruct), 0);
    sh.Wnd := Application.Handle;
    sh.wFunc := fo_Move;
    sh.pFrom := PChar(AOldName + #0);
    sh.pTo := PChar(ANewName + #0);
    sh.fFlags := fof_Silent or FOF_NOCONFIRMATION or FOF_NOERRORUI;
    Result := ShFileOperation(sh) = 0;
  except
    Result := false;
  end;
end;
und hier die Timer Routine:
Delphi-Quellcode:
procedure TFmMain.ExportTimerTimer(Sender: TObject);
begin
  if ( not FmOption.checkOptions( CheckExport ) ) then
    LogExport( 'Options empty, please check!' )
  else if ( not FmOption.RegExpEnable ) then

  else
    DoExport();

end;

procedure TFmMain.doExport();
var
  Search: TSearchRec;
  FileList: TStringList;
  FilePath: String;
  i: integer;
begin
  if ( DoingExport ) then

  else
  begin
    DoingExport := true;
    ExportCounter := ExportCounter + 1;
    FileList := TStringList.Create();

    if ( FindFirst( FmOption.RegExpPath + '\*.*', faAnyFile, Search ) = 0 ) then
    begin
      try
        repeat
          if ( (Search.Name <> '.') and
               (Search.Name <> '..')) then begin
            FileList.Add( Search.Name );
          end;
        until FindNext( Search ) <> 0;
      finally
        FindClose( Search );
      end;
    end;

    FileList.Sort();

    for i := 0 to FileList.Count - 1 do
    begin
      FilePath := FmOption.RegExpPath + '\' + FileList[i];
      exportFile( FilePath, true );
    end;

    DoingExport := false;

    if (ExportCounter mod 10 = 0 ) then
      LogExport( '--- Mark ---' );
  end;
end;

procedure TFmMain.exportFile( const filepath: string;const remove: boolean );
var
  FileName,
  FileTmp,
  Path: string;
  Stream: TIdMultiPartFormDataStream;
  Resp: TMemoryStream;
  result: Boolean;
begin
  filename := ExtractFileName( filepath );
  Stream := TIdMultiPartFormDataStream.Create;
  Resp := TMemoryStream.Create();
  result := true;
  Resp.Clear();
  Resp.Seek( 0, soFromBeginning );

  try
    if ( remove ) then
    begin
      Path := FmOption.RegTmpPath;
      FileTmp := FmOption.RegTmpPath + '\' + FileName;
      if ( not MoveFile( FilePath, FileTmp ) ) then
      begin
        LogExport( '[Error] Can''t move file ' + FilePath + ' to ' + FileTmp );
        result := false;
      end;
    end
    else
    begin
      Path := ExtractFilePath( FilePath );
      FileTmp := FilePath;
    end;

    if ( result ) then
    begin
      chdir( Path );
      Stream.AddFile( 'file', FileName, 'text/plain' );

      HTTPClient.Request.Username := FmOption.RegUsername;
      HTTPClient.Request.Password := FmOption.RegPassword;
      HTTPClient.Request.BasicAuthentication := true;
      HTTPClient.Post( 'https://' + FmOption.RegServer + '/files/import',
                       Stream, Resp );

      lbExpLastFile.Caption := 'Last filename: ' + FileName;
      lbExpLastFile.Width := 220;

    end;
  except
    on e : exception do
    begin
      LogExport( '[Error] sending file ' + FileName );
      result := false;
    end;
  end;

  Stream.Destroy();
  Resp.Seek(0,soFromBeginning);
  Resp.Free;

  if ( result ) then
    if ( remove and not RemoveFile( FileTmp ) ) then
      LogExport( '[Error] Can''t delete file ' + FileTmp )
    else
      LogExport( 'Export: ' + FileName )
  else
    if ( remove and not MoveFile( FileTmp, FilePath ) ) then
      LogExport( '[Error] Can''t export file and move file ' + FileTmp + ' to ' + FilePath )
    else
      LogExport( '[Error] Can''t export file ' + FileName );
end;
Falls noch die anderen Proceduren benötigt werden nur fragen

Danke und Gruss

Tobias
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz