diff options
author | genotrance <dev@genotrance.com> | 2018-04-10 11:50:23 -0500 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-04-10 18:50:23 +0200 |
commit | f6c8f97fe8bd22e7a2c1b9463f52747e98693682 (patch) | |
tree | aaf353540fa35d16dffaca60c8c7b26e4a543613 /lib | |
parent | 16c1a90857992df0960f53f5ffa578f14059cee4 (diff) | |
download | Nim-f6c8f97fe8bd22e7a2c1b9463f52747e98693682.tar.gz |
Add a few useful os calls to nimscript (#7442)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/nimscript.nim | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim index cb9f0ab01..7671e5962 100644 --- a/lib/system/nimscript.nim +++ b/lib/system/nimscript.nim @@ -38,13 +38,19 @@ proc removeFile(dir: string) {. tags: [ReadIOEffect, WriteIOEffect], raises: [OSError].} = builtin proc moveFile(src, dest: string) {. tags: [ReadIOEffect, WriteIOEffect], raises: [OSError].} = builtin +proc moveDir(src, dest: string) {. + tags: [ReadIOEffect, WriteIOEffect], raises: [OSError].} = builtin proc copyFile(src, dest: string) {. tags: [ReadIOEffect, WriteIOEffect], raises: [OSError].} = builtin +proc copyDir(src, dest: string) {. + tags: [ReadIOEffect, WriteIOEffect], raises: [OSError].} = builtin proc createDir(dir: string) {.tags: [WriteIOEffect], raises: [OSError].} = builtin proc getOsError: string = builtin proc setCurrentDir(dir: string) = builtin -proc getCurrentDir(): string = builtin +proc getCurrentDir*(): string = + ## Retrieves the current working directory. + builtin proc rawExec(cmd: string): int {.tags: [ExecIOEffect], raises: [OSError].} = builtin @@ -117,7 +123,7 @@ proc existsEnv*(key: string): bool {.tags: [ReadIOEffect].} = proc putEnv*(key, val: string) {.tags: [WriteIOEffect].} = ## Sets the value of the environment variable named key to val. builtin - + proc fileExists*(filename: string): bool {.tags: [ReadIOEffect].} = ## Checks if the file exists. builtin @@ -206,12 +212,24 @@ proc mvFile*(`from`, to: string) {.raises: [OSError].} = moveFile `from`, to checkOsError() +proc mvDir*(`from`, to: string) {.raises: [OSError].} = + ## Moves the dir `from` to `to`. + log "mvDir: " & `from` & ", " & to: + moveDir `from`, to + checkOsError() + proc cpFile*(`from`, to: string) {.raises: [OSError].} = ## Copies the file `from` to `to`. log "cpFile: " & `from` & ", " & to: copyFile `from`, to checkOsError() +proc cpDir*(`from`, to: string) {.raises: [OSError].} = + ## Copies the dir `from` to `to`. + log "cpDir: " & `from` & ", " & to: + copyDir `from`, to + checkOsError() + proc exec*(command: string) = ## Executes an external process. log "exec: " & command: @@ -265,6 +283,12 @@ proc cd*(dir: string) {.raises: [OSError].} = setCurrentDir(dir) checkOsError() +proc findExe*(bin: string): string = + ## Searches for bin in the current working directory and then in directories + ## listed in the PATH environment variable. Returns "" if the exe cannot be + ## found. + builtin + template withDir*(dir: string; body: untyped): untyped = ## Changes the current directory temporarily. ## |