py-mactypes manual | 3. File class

#

## 3. The `File` class

The `File` class represents a fixed filesystem location which may or may not already exist.

### Methods

    File -- A reference to a fixed filesystem location which may or may not
            already exist. Provides a variety of properties and constructors
            for converting to and from other Python types.

        Constructors:

            File(path) -- make File object from POSIX path

    	File.makewithhfspath(path) -- make File object from HFS path

            File.makewithurl(url) -- make File object from file URL

            File.makewithdesc(desc) -- make File object from
                    aem.ae.AEDesc of typeFileURL

        Properties:

            path : unicode -- POSIX path

    	hfspath : unicode -- HFS path

            url : string -- file URL

            file : mactypes.File -- a new File object

            alias : mactypes.Alias

            desc : aem.ae.AEDesc

### Examples

    from appscript import *
    from mactypes import *

    f = File('/Users/foo/some file')

    print f
    # mactypes.File("/Users/foo/some file")

    print f.path
    # /Users/foo/some file

    print f.url
    # file://localhost/Users/foo/some%20file

    app('TextEdit').documents[1].save(in_=f)
    # saves front TextEdit document at the given location

### Notes

When creating a `File` instance, POSIX paths may be either relative or absolute and are automatically normalised using `os.path.abspath`.

When comparing `File` objects for equality, `File.__eq__` will perform a case-sensitive comparison of their file paths. Client that need to perform (for example) case-insensitive comparisons should obtain path strings from each `File` object, then normalise and compare those values as necessary.

The `File` class normally wraps AEDescs of `typeFileURL`, which can represent both existing and non-existing locations. For legacy compatibility with older Carbon apps, it can also wrap existing AEDescs of `typeFSRef` or `typeFSS`, although these obsolete Carbon types are long since deprecated and should not be used now.