JXA $.NSFileManager 関連

使用OS: macOS 10.12

ファイルマネージャーの取得
===

```js
fm = $.NSFileManager.defaultManager
```

ディレクトリの作成
===

```js
p = '/tmp/hoge/fuga/foo/bar/'
i = 1 // or 0
a = $()
e = $()
fm.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(p, i, a, e)
// => true, e => $()
```

ファイルの作成
===

```js
p = '/tmp/a.txt'
c = $.NSData.data //ゼロデータ
a = $()
fm.createFileAtPathContentsAttributes(p, c, a)
// => true
```

存在確認
===

```js
fm.fileExistsAtPath('/bin/sh')
// => true

fm.fileExistsAtPath('/bin/')
// => true

fm.fileExistsAtPath('/private/hogehoge/')
// => false

isDir = Ref()
fm.fileExistsAtPathIsDirectory('/bin/', isDir)
// => true, isDir[0] => 1

isDir = Ref()
fm.fileExistsAtPathIsDirectory('/bin/sh', isDir)
// => true, isDir[0] => 0
```

種別確認
===

```js
e = $()
a = fm.attributesOfItemAtPathError('/bin/', e)
a.objectForKey($.NSFileType).js === $.NSFileTypeDirectory.js
// => true, e => $()

a = fm.attributesOfItemAtPathError('/tmp/a-symbolic-link', e)
a.objectForKey($.NSFileType).js === $.NSFileTypeSymbolicLink.js
// => true, e => $()
```

ファイル同一内容確認
===

```js
fm.contentsEqualAtPathAndPath('/tmp/a.txt','/tmp/b.txt')
// => true or false
```

移動または名称変更
===

```js
at = '/tmp/a.txt'
to = '/tmp/d.txt'
e = $()
fm.moveItemAtPathToPathError(at, to, e)
// => true, e => $()
```

複製
===

```js
at = '/tmp/d.txt'
to = '/tmp/a.txt'
e = $()
fm.copyItemAtPathToPathError(at, to, e)
// => true, e => $()
```

削除
===

```js
p = '/tmp/d.txt'
e = $()
fm.removeItemAtPathError(p, e)
// => true, e => $()
```

リンク
===

```js
at = '/tmp/a.txt'
to = '/tmp/a-hard-ln.txt'
e = $()
fm.linkItemAtPathToPathError(at, to, e)
// => true, e => $()

at = '/tmp/a-symbolic-ln.txt'
de = '/tmp/a.txt'
e = $()
fm.createSymbolicLinkAtPathWithDestinationPathError(at, de, e)
// => true, e => $()

p = '/tmp/a-symbolic-ln.txt'
e = $()
fm.destinationOfSymbolicLinkAtPathError(p, e)
// => $("/tmp/a.txt"), e => $()
```

パーミッションの設定と確認
===

```js
a = $({'NSFilePosixPermissions':0777})
p = '/tmp/c.sh'
e = $()
fm.setAttributesOfItemAtPathError(a, p, e)
// => true, e => $()

fm.isReadableFileAtPath(p)
// => true
fm.isWritableFileAtPath(p)
// => true
fm.isDeletableFileAtPath(p)
// => true
fm.isExecutableFileAtPath(p)
// => true
```

読み込み・書き込み
===

```js
p = '/tmp/a.txt'
u = $.NSUTF8StringEncoding
c = $('本日は晴天なり\n').dataUsingEncoding(u)
a = $()
fm.createFileAtPathContentsAttributes(p, c, a)
// => true, e => $()

d = fm.contentsAtPath(p)
// => [id NSConcreteData]
$.NSString.alloc.initWithDataEncoding(d, u)
// => $("本日は晴天なり\n")

d = fm.contentsAtPath('/tmp/hogehoge.txt')
// => $()
$.NSString.alloc.initWithDataEncoding(d, u)
// => $("")
```

作業ディレクトリの変更と現在位置
===

```js
p = '/private/tmp/'
fm.changeCurrentDirectoryPath(p)
// => true
p = '/private/hoge/'
fm.changeCurrentDirectoryPath(p)
// => false
fm.currentDirectoryPath
// => $("/private/tmp/")
```

一覧
===

```js:ls.js
p = fm.currentDirectoryPath
fm.directoryContentsAtPath(p)

c = fm.directoryContentsAtPath(p)
c = ObjC.deepUnwrap(c)
d = fm.currentDirectoryPath.js
c.filter((name)=>{var isDir=Ref();var result=fm.fileExistsAtPathIsDirectory(d+"/"+name,isDir);return result&&isDir[0]?true:false;})

c = fm.directoryContentsAtPath(p)
c = ObjC.deepUnwrap(c)
d = fm.currentDirectoryPath.js
c.filter((name)=>{var isDir=Ref();var result=fm.fileExistsAtPathIsDirectory(d+"/"+name,isDir);return result&&!isDir[0]?true:false;})
```

```js:find.js
p = fm.currentDirectoryPath
c = fm.subpathsAtPath(p)
ObjC.deepUnwrap(c).forEach(content=>{console.log(content)})
```

```js:tree.js
p = '/private/tmp/'
fm.changeCurrentDirectoryPath(p)
p = fm.currentDirectoryPath
c = fm.enumeratorAtPath(p)
content=c.nextObject.js; do {console.log(content);content=c.nextObject.js;} while(content)
```