So first off, sorry for the extremely noobie question, I've never really used compiled languages before so I'm struggling a bit with the concept.
I'm trying to write a small chunk of code that reads the contents of a directory and returns a list of items in that directory sans a specific file extension.
For example, imagine a directory like this
├ Font-Black.otf
├ Font-Black.ttf
├ Font-Black.woff
└ Font-Black.woff2
In the end, it should print out [Font-Black].
The issue I'm running into now is that Nim doesn't know what the File path is at compile time, so I can't use re.replacef() on it.
My code (I know that it won't make the list unique, but for now I don't care about that part):
import os, std/re
var directory_contents: seq[string]
for file in walkDir("./", true):
let
file_name = file.path
file_regex = re(".+(ttf|otf|eot|woff2?)")
if match(file_name, file_regex):
const chomped_file = replacef(file_name, file_regex, "$1")
directory_contents.add(file.path)
else:
discard
echo directory_contents
Which gives me a compile-time error, Error: cannot evaluate at compile time: file_name.
Is there any way for me to get this to work? I think there's just a fundamental misunderstanding with how this works exactly.
To explain a bit more - in Nim var, let and const have (IMO) more consistent meanings that in other languages - they don't modify the variable's scope, they affect immutability and runtime vs compile-time.