TDirectory is a class in the IOUtils unit that provides a set of static methods for working with directories. You can use these methods to perform various operations on directories, such as creating, deleting, and renaming directories, as well as enumerating the files and subdirectories contained within a directory.
Here are some examples of how you can use TDirectory in Delphi
To create a new directory, use the CreateDirectory method;
1 |
TDirectory.CreateDirectory(‘CMyDirectory’); |
To delete an existing directory, use the DeleteDirectory method;
1 |
TDirectory.DeleteDirectory(‘CMyDirectory’, False); |
To rename an existing directory, use the MoveDirectory method;
1 |
TDirectory.MoveDirectory(‘CMyDirectory’, ‘CMyNewDirectory’); |
To retrieve a list of all the files in a directory, use the GetFiles method;
1 2 3 4 5 6 7 8 9 10 |
var FileList: TStringDynArray; FileName: string; begin FileList := TDirectory.GetFiles(‘CMyDirectory’); for FileName in FileList do begin //Do something with the file end; end; |
To retrieve a list of all the subdirectories in a directory, use the GetDirectories method;
1 2 3 4 5 6 7 8 9 10 |
var DirList: TStringDynArray; DirName: string; begin DirList := TDirectory.GetDirectories(‘CMyDirectory’); for DirName in DirList do begin //Do something with the subdirectory end; end; |
You can find more information about the methods provided by TDirectory in the Delphi documentation.
Leave a Reply