Home  |  Delphi .net Home  |  System.IO.Directory  |  Move Method
  
Move  
Method  
Move a File or Directory to a new location
Directory Class
System.IO NameSpace
CF1.  Procedure Move ( SourcePath : String; TargetPath : String ) ; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Moves the SourcePath file or folder to the TargetPath file or folder.
 
For a folder move, the TargetPath folder must not yet exist - the target is the name of the new folder, not its location.
Notes
Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System.IO
System.IO.Directory
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  BasePath : String;
  Folders  : Array of String;
  i        : Integer;

begin
  // Create a base folder
  BasePath := 'C:\Base';
  System.IO.Directory.CreateDirectory(BasePath);

  // And a sub-folder
  System.IO.Directory.CreateDirectory(BasePath+'\SubFolder');

  // List the folders under C:\Base
  Folders := System.IO.Directory.GetDirectories(BasePath);

  for i := 0 to Length(Folders)-1 do
    Console.WriteLine(Folders[i]);

  // Now move the sub folder to a new name
  System.IO.Directory.Move(BasePath+'\SubFolder', BasePath+'\NewFolder');

  // List the folders under C:\Base
  Folders := System.IO.Directory.GetDirectories(BasePath);

  for i := 0 to Length(Folders)-1 do
    Console.WriteLine(Folders[i]);

  // Now delete this nest of folders
  System.IO.Directory.Delete(BasePath, true);

  Console.Readline;
end.
   C:\Base\SubFolder
   C:\Base\NewFolder
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author