Einzelnen Beitrag anzeigen

Schokohase
(Gast)

n/a Beiträge
 
#34

AW: Pfadinhalte eine Ebene aufwärts kopieren

  Alt 20. Sep 2018, 09:45
Ich hätte jetzt eher an so etwas gedacht
Delphi-Quellcode:
program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils,
  System.IOUtils;

procedure MoveDirectoryContentOneUp( const ASource: string );
var
  srcPath, dstPath: string;
  srcEntry, dstEntry: string;
begin
  srcPath := IncludeTrailingPathDelimiter( TPath.GetFullPath( ASource ) );
  dstPath := IncludeTrailingPathDelimiter( ExpandFileName( TPath.Combine( srcPath, '..' ) ) );

  for srcEntry in TDirectory.GetDirectories( srcPath ) do
    begin
      dstEntry := TPath.Combine( dstPath, ExtractRelativePath( srcPath, srcEntry ) );
      TDirectory.Move( srcEntry, dstEntry );
    end;

  for srcEntry in TDirectory.GetFiles( srcPath ) do
    begin
      dstEntry := TPath.Combine( dstPath, ExtractRelativePath( srcPath, srcEntry ) );
      TFile.Move( srcEntry, dstEntry );
    end;
end;

begin
  try
    MoveDirectoryContentOneUp( 'C:\tmp\alt' );
  except
    on E: Exception do
      Writeln( E.ClassName, ': ', E.Message );
  end;

end.
Wenn man mit den Pfadangeben herumspielen möchte, dann sollte man auch die entsprechenden Funktionen zum Herumspielen verwenden.

Geändert von Schokohase (20. Sep 2018 um 09:48 Uhr)
  Mit Zitat antworten Zitat