at this page: https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#Reading-and-writing-files
Example:
import fusion/scripting
withDir "subfolder":
echo "Inside subfolder"
echo "Go back outside subfolder"
fails with error message: Error: cannot open file: fusion
Minimum reproducible example:
import fusion
My goal:
wow - creating a new directory is very easy: https://nim-lang.org/docs/os.html#createDir%2Cstring
createDir "/Volumes/T7/Folder2/"
hopefully this is idiomatic / correct Nim approach:
import os, re
for file in walkDirRec "/Volumes/T7/Folder/":
if file.match re".*\.txt":
echo file
createDir "/Volumes/T7/Folder2/" # just to test creation of a folder
# this is the actual solution - copy folder and all the files
copyDir "/Volumes/T7/Folder/", "/Volumes/T7/Folder3/"
You don't need regular expressions for that kind of matching. Usually, I have seen use of regex only if it necessary.
For your example file.endsWith(".txt") would work. You'll need to import std/[strutils] for that.