Working with Files

Like the Directory and DirectoryInfo classes, File and FileInfo classes exist in the System.IO namespace that provide the functionality for manipulating files. Because the directory and file classes descend from the same base class, they contain some of the same properties, and using them is almost identical.

Creating and Deleting Files

There are more than a few ways to create a file. One is to use the File.CreateText() method to create a text file. This method returns a StreamWriter that allows you to write to the file. This technique is illustrated here:

var sw: StreamWriter; begin if not System.IO.File.Exists('c:\deleteme.txt') then begin sw := System.IO.File.CreateText('c:\deleteme.txt'); try sw.Write('hello world'); finally ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.