File: tfilesanddirs.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (36 lines) | stat: -rw-r--r-- 961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import std/[paths, files, dirs, appdirs]

from stdtest/specialpaths import buildDir
import std/[syncio, assertions]

block fileOperations:
  let files = @[Path"these.txt", Path"are.x", Path"testing.r", Path"files.q"]
  let dirs = @[Path"some", Path"created", Path"test", Path"dirs"]

  let dname = Path"__really_obscure_dir_name"

  createDir(dname.Path)
  doAssert dirExists(Path(dname))
 
  # Test creating files and dirs
  for dir in dirs:
    createDir(Path(dname/dir))
    doAssert dirExists(Path(dname/dir))

  for file in files:
    let fh = open(string(dname/file), fmReadWrite) # createFile
    fh.close()
    doAssert fileExists(Path(dname/file))

block: # getCacheDir
  doAssert getCacheDir().dirExists

block: # moveFile
  let tempDir = getTempDir() / Path("D20221022T151608")
  createDir(tempDir)
  defer: removeDir(tempDir)

block: # moveDir
  let tempDir = getTempDir() / Path("D20220609T161443")
  createDir(tempDir)
  defer: removeDir(tempDir)