How to "touch" a file using Swift on OSX -


i touch folder using swift using native command similar command line:

touch myfile.txt

what best way of doing this?

i can create folders ok. question how touch folder (ie update modification date) without affecting folders contents.

i exploring whether there api this. expect can invoke cli command this. research has not turned satisfactory answer.

no need invoking cli command, can nsfilemanager.

first, let's have @ attributes of file (or folder):

let manager = nsfilemanager()  {     let attr = try manager.attributesofitematpath(yourfilepath)     print(attr) } catch let error nserror {     print(error) } 

what .attributesofitematpath nsdictionary containing file/folder attributes, including modification date.

you can set these attributes .setattributes, here's example setting modification date current date:

let newattributes = [nsfilemodificationdate: nsdate()]  {     try manager.setattributes(newattributes, ofitematpath: yourfilepath) } catch let error nserror {     print(error) } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -