-2

I cannot seem to be able to call ForceDirectories() on a NAS partition on Windows 10 64-bit.

I can create a folder on the NAS using Windows Explorer just fine.

procedure TForm3.Button1Click(Sender: TObject);
var
  tempDir: String;
begin
  tempDir := 'z:\ttt\ttttest';
  if NOT DirectoryExists(tempDir) then
    if System.SysUtils.ForceDirectories(tempDir) then
      ShowMessage('Dir: ' + tempDir + ' Forced alright')
    else
      ShowMessage('Dir: ' + tempDir + ' Force FAILED with error : '+ IntToStr(GetLastError));
end; 

Z: is the Western Digital Network Attached Storage which works fine in all other respects.

The code returns error 3 every time.

Same code works correctly on local drives.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Seti Net
  • 693
  • 1
  • 7
  • 24
  • 1
    Works fine for me. Probably a mapping for permission issue locally. One wonders if you are running delphi ide as admin. – David Heffernan Mar 02 '16 at 22:02
  • Also, I trust you know what 3 means here: https://msdn.microsoft.com/en-gb/library/windows/desktop/ms681382(v=vs.85).aspx – David Heffernan Mar 02 '16 at 22:11
  • 8
    Error 3 is `ERROR_PATH_NOT_FOUND`. Drive letter mappings are per-user, so chances are that the `Z:` drive does not exist for the user account that is running your app. Also, `ForceDirectories()` checks if the directory exists before creating it, so you don't need to call `DirectoryExists()` manually. – Remy Lebeau Mar 02 '16 at 22:43
  • Still not working. There must be something basically wrong. Every other tool I use manages to create and access folders on the NAS fine (Directory Opus, File Explorer, MS Word, NotePad++) all of them. Any other ideas? – Seti Net Mar 04 '16 at 17:57
  • I do run Delphi as an administrator and have tested to make sure the app runs under my administrator user. – Seti Net Mar 04 '16 at 18:07
  • That's your problem. You are running the process in a context without the drive mapped. As a rule, running delphi elevated is a terrible idea. Stop it. – David Heffernan Mar 04 '16 at 19:14

1 Answers1

0

You are running your IDE as admin. That means that your process also runs as admin. And it seem that when run as admin, the drive mapping to the NAS drive is not available.

My advice is not to run your IDE as admin.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490