EFCreateError
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
EFCreateError is raised when Delphi cannot create a file. The full error message usually says 'Cannot create file X: Access is denied' or 'Cannot create file X: The system cannot find the path specified'. Common causes: the folder does not exist, the application lacks write permission, or the disk is full. The fix is to check that the destination folder exists, that your application has write access, and that there is free disk space.
Affected Models
- Delphi 2
- Delphi 7
- Delphi XE
- Delphi 10.x
- Delphi 11
- Delphi 12
- All modern Delphi versions
Common Causes
- The destination folder does not exist and Delphi cannot create a file in a non-existent folder
- The application does not have write permission to the folder — common when writing to Program Files or Windows system folders
- The disk is full and there is no space to create the file
- The file is locked by another process (open in another application or another thread)
- A network path is unavailable or the network drive is disconnected
How to Fix It
-
Check that the destination folder exists before trying to create a file in it. Use DirectoryExists() and ForceDirectories() to create it if needed.
Example: if not DirectoryExists(FolderPath) then ForceDirectories(FolderPath);
-
If writing to Program Files, Windows, or other system folders, your application needs to run as Administrator — or better, write to a user-appropriate folder instead.
Modern Windows requires administrator privileges to write to Program Files. Use GetSpecialFolderPath(CSIDL_APPDATA) or TPath.GetDocumentsPath to get a writeable user data folder.
-
Wrap the file creation in a try/except block to catch EFCreateError and show a meaningful message to the user.
Example: try TFileStream.Create(FileName, fmCreate); except on E: EFCreateError do ShowMessage('Cannot create file: ' + E.Message); end;
-
Check if the file is already open somewhere. A file that is open by another process (or your own program in another thread) cannot be created or overwritten.
Use FileExists() to check if the file already exists. If it does, check whether it can be opened with fmOpenWrite or if it is locked.
-
Check available disk space using DiskFree() before writing large files: if DiskFree(0) < RequiredBytes then ShowMessage('Not enough disk space');
DiskFree(0) returns free bytes on the current drive. Pass a drive number (1=A, 2=B, 3=C, etc.) for a specific drive.
When to Call a Professional
EFCreateError is usually straightforward to fix. Check folder existence, write permissions, and disk space first. For production applications, always wrap file creation in a try/except block to handle failures gracefully.
Frequently Asked Questions
What is the difference between EFCreateError and EFOpenError?
EFCreateError is raised when creating a NEW file fails. EFOpenError is raised when opening an EXISTING file fails. Both are subclasses of EStreamError (which is in the SysUtils unit). They have similar causes — permissions, missing paths, locked files — but apply to different file operations.
Where should a Delphi application store its data files?
For user-specific data: use the AppData folder — GetEnvironmentVariable('APPDATA') + '\YourAppName\' For shared data: use ProgramData — GetEnvironmentVariable('PROGRAMDATA') + '\YourAppName\' NEVER write to the application's own folder (Program Files) on modern Windows — UAC blocks it. Use the SHGetFolderPath API or Delphi's TPath class for reliable cross-version paths.
How do I create a folder structure before saving a file?
Use ForceDirectories(Path) — it creates the full path including any missing parent folders, similar to 'mkdir -p' on Linux. Example: ForceDirectories('C:\MyApp\Data\Reports\') creates all folders in the path. ForceDirectories returns True if the directories were created or already exist, False on failure. Always check the return value or wrap in try/except.