tfilesanddirs.nim 961 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import std/[paths, files, dirs, appdirs]
  2. from stdtest/specialpaths import buildDir
  3. import std/[syncio, assertions]
  4. block fileOperations:
  5. let files = @[Path"these.txt", Path"are.x", Path"testing.r", Path"files.q"]
  6. let dirs = @[Path"some", Path"created", Path"test", Path"dirs"]
  7. let dname = Path"__really_obscure_dir_name"
  8. createDir(dname.Path)
  9. doAssert dirExists(Path(dname))
  10. # Test creating files and dirs
  11. for dir in dirs:
  12. createDir(Path(dname/dir))
  13. doAssert dirExists(Path(dname/dir))
  14. for file in files:
  15. let fh = open(string(dname/file), fmReadWrite) # createFile
  16. fh.close()
  17. doAssert fileExists(Path(dname/file))
  18. block: # getCacheDir
  19. doAssert getCacheDir().dirExists
  20. block: # moveFile
  21. let tempDir = getTempDir() / Path("D20221022T151608")
  22. createDir(tempDir)
  23. defer: removeDir(tempDir)
  24. block: # moveDir
  25. let tempDir = getTempDir() / Path("D20220609T161443")
  26. createDir(tempDir)
  27. defer: removeDir(tempDir)