about summary refs log tree commit diff stats
path: root/src/extern/tempfile.nim
blob: d99ea4dc336e8fa564ccd644aa7098ea875ab478 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os

var tmpf_seq: int
proc getTempFile*(tmpdir: string, ext = ""): string =
  if not dirExists(tmpdir):
    createDir(tmpdir)
  var tmpf = tmpdir / "chatmp" & $tmpf_seq
  if ext != "":
    tmpf &= "."
    tmpf &= ext
  while fileExists(tmpf):
    inc tmpf_seq
    tmpf = tmpdir / "chatmp" & $tmpf_seq
    if ext != "":
      tmpf &= "."
      tmpf &= ext
  inc tmpf_seq
  return tmpf