Home Delphi Berlin 10.1 create file/folder OS X
Reply: 1

Delphi Berlin 10.1 create file/folder OS X

artemk
1#
artemk Published in 2018-02-12 15:16:12Z

How to create file/folder on OS X via delphi? I'm trying to use functions

System.SysUtils.FileCreate

And

System.IOUtils.TDirectory.CreateDirectory

Code:

  if FileCreate('/var/folders/bla.txt') = INVALID_HANDLE_VALUE then
 raise Exception.Create('File already exists');

or

 `TDirectory.CreateDirectory('/var/folders/mydirdelete');`

Anyway when i run app i get

Exception EFileNotFoundException in module blprtl240.dylib at 0053AFAF.
The specified file was not found. 

Even if i create folder.

Any advices?

RepeatUntil
2#
RepeatUntil Reply to 2018-02-12 17:06:22Z

The docs says FileCreate return INVALID_HANDLE_VALUE (-1) indicates that an error occurred which not only mean that file already exists e.g. it could be Permission denied ...etc.

Regarding CreateDirectory raises an exception if the given Path is invalid or contains invalid characters.

Try this instead:

const
  AFilename = '/tmp/folders/bla.txt';
begin
  if NOT FileExists(AFilename) then begin
    if NOT DirectoryExists(ExtractFilePath(AFilename)) then
      if NOT ForceDirectories(ExtractFilePath(AFilename)) then RaiseLastOSError;
    if (FileCreate(AFilename) = INVALID_HANDLE_VALUE) then RaiseLastOSError;
  end;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302485 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO