i'm writing script in swift, , want modify files exist in same directory script itself. there way path script within itself? tried:
print(process.arguments) but outputs path given script, may resolved path, file name, or in between.
i'm intending script run swift /path/to/my/script.swift.
just in swift:
let cwd = filemanager.default.currentdirectorypath print("script run from:\n" + cwd) let script = commandline.arguments[0]; print("\n\nfilepath given script:\n" + script) //get script working dir if script.hasprefix("/") { //absolute let path = (script nsstring).deletinglastpathcomponent print("\n\nscript at:\n" + path) } else { let urlcwd = url(fileurlwithpath: cwd) if let path = url(string: script, relativeto: urlcwd)?.path { let path = (path nsstring).deletinglastpathcomponent print("\n\nscript at:\n" + path) } }
Comments
Post a Comment