mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-27 09:43:58 +00:00
adds more functions to to dirs and files (#25083)
ref https://forum.nim-lang.org/t/13272
This commit is contained in:
@@ -30,6 +30,9 @@ Raises
|
||||
from stdtest/specialpaths import buildDir
|
||||
import std/[syncio, assertions, osproc, os, strutils, pathnorm]
|
||||
|
||||
import std/paths except getCurrentDir
|
||||
import std/[files, dirs]
|
||||
|
||||
block fileOperations:
|
||||
let files = @["these.txt", "are.x", "testing.r", "files.q"]
|
||||
let dirs = @["some", "created", "test", "dirs"]
|
||||
@@ -52,11 +55,11 @@ block fileOperations:
|
||||
doAssertRaises(OSError): copyFile(file, dname/sub/fname2)
|
||||
doAssertRaises(OSError): copyFileToDir(file, dname/sub)
|
||||
doAssertRaises(ValueError): copyFileToDir(file, "")
|
||||
copyFile(file, file2)
|
||||
copyFile(Path file, Path file2)
|
||||
doAssert fileExists(file2)
|
||||
doAssert readFile(file2) == str
|
||||
createDir(dname/sub)
|
||||
copyFileToDir(file, dname/sub)
|
||||
copyFileToDir(Path file, Path dname/sub)
|
||||
doAssert fileExists(dname/sub/fname)
|
||||
removeDir(dname/sub)
|
||||
doAssert not dirExists(dname/sub)
|
||||
@@ -131,12 +134,13 @@ block fileOperations:
|
||||
removeDir(dname)
|
||||
|
||||
# test copyDir:
|
||||
createDir("a/b")
|
||||
createDir(Path "a/b")
|
||||
open("a/b/file.txt", fmWrite).close
|
||||
createDir("a/b/c")
|
||||
open("a/b/c/fileC.txt", fmWrite).close
|
||||
|
||||
copyDir("a", "../dest/a")
|
||||
createDir(Path"a/b")
|
||||
copyDir(Path "a", Path "../dest/a")
|
||||
removeDir("a")
|
||||
|
||||
doAssert dirExists("../dest/a/b")
|
||||
@@ -169,7 +173,7 @@ block fileOperations:
|
||||
doAssert execCmd("mkfifo -m 600 a/fifoFile") == 0
|
||||
|
||||
copyDir("a/", "../dest/a/", skipSpecial = true)
|
||||
copyDirWithPermissions("a/", "../dest2/a/", skipSpecial = true)
|
||||
copyDirWithPermissions(Path "a/", Path "../dest2/a/", skipSpecial = true)
|
||||
removeDir("a")
|
||||
|
||||
# Symlink handling in `copyFile`, `copyFileWithPermissions`, `copyFileToDir`,
|
||||
|
||||
Reference in New Issue
Block a user