Last active
July 2, 2017 08:05
-
-
Save uchcode/fcf2b1e442d0660556fc0110d26b5ab8 to your computer and use it in GitHub Desktop.
JXA $.NSFileManager 関連 ref: http://qiita.com/tom-u/items/6c1d7ece71d9d4e84f1f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fm = $.NSFileManager.defaultManager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p = '/tmp/hoge/fuga/foo/bar/' | |
| i = 1 // or 0 | |
| a = $() | |
| e = $() | |
| fm.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(p, i, a, e) | |
| // => true, e => $() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| // => $("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p = '/private/tmp/' | |
| fm.changeCurrentDirectoryPath(p) | |
| // => true | |
| p = '/private/hoge/' | |
| fm.changeCurrentDirectoryPath(p) | |
| // => false | |
| fm.currentDirectoryPath | |
| // => $("/private/tmp/") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p = '/tmp/a.txt' | |
| c = $.NSData.data //ゼロデータ | |
| a = $() | |
| fm.createFileAtPathContentsAttributes(p, c, a) | |
| // => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 => $() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fm.contentsEqualAtPathAndPath('/tmp/a.txt','/tmp/b.txt') | |
| // => true or false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| at = '/tmp/a.txt' | |
| to = '/tmp/d.txt' | |
| e = $() | |
| fm.moveItemAtPathToPathError(at, to, e) | |
| // => true, e => $() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| at = '/tmp/d.txt' | |
| to = '/tmp/a.txt' | |
| e = $() | |
| fm.copyItemAtPathToPathError(at, to, e) | |
| // => true, e => $() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p = '/tmp/d.txt' | |
| e = $() | |
| fm.removeItemAtPathError(p, e) | |
| // => true, e => $() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 => $() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p = fm.currentDirectoryPath | |
| c = fm.subpathsAtPath(p) | |
| ObjC.deepUnwrap(c).forEach(content=>{console.log(content)}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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;}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment