Check ability to write to nonexistent directory

  • Hello,

    I would like to be able to use a function similar to NSFileManager's
    isWritableFileAtPath: to determine if I can write to a certain
    directory, but in this case the folder might not exist yet. For
    example, a Download folder in Documents might not exist, but i would
    like to be able to pass in the path and see 1. if it does exist, can I
    write to it/read from it? 2. if it doesn't exist, can if be created,
    and then can I write to it? Is there a function for this?

    Cheers,
    Mitch
  • On 18 Jan 2008, at 17:11, Mitchell Livingston wrote:

    > I would like to be able to use a function similar to NSFileManager's
    > isWritableFileAtPath: to determine if I can write to a certain
    > directory, but in this case the folder might not exist yet. For
    > example, a Download folder in Documents might not exist, but i would
    > like to be able to pass in the path and see 1. if it does exist, can
    > I write to it/read from it? 2. if it doesn't exist, can if be
    > created, and then can I write to it? Is there a function for this?

    There are certainly functions you can use, but it's generally best
    just to try writing to it and only then start trying to handle the
    situation where you can't.  Why?  Because on a multitasking system
    like Mac OS X, some other program could create, delete or modify the
    folder you're trying to save to between your tests and your actual
    write.  In the worst case, this can actually create a security hole,
    since it might be used by another user to cause a more privileged user
    to write to the wrong place, with potentially catastrophic consequences.

    Ideally, the only time you should be examining folders like this is
    where you're just using the information for display purposes.  e.g.
    Finder's indication as to whether a folder is write-able or not.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today