Closed wraikny closed 2 years ago
One way to ensure the existence of the file is to use the non-parameterized version of the provider, ie instead of TextFile<"foo/bar.txt">
, use TextFile.foo.``bar.txt``
.
But now I realize that you might want to provide the path as a string anyway (perhaps because it itself comes from another LiteralProvider), so yeah then this makes sense.
In my situation I had to specify the file path of the project's parent hierarchy (for example, ../../misc/foobar.txt
). In any case, thank you for your consideration.
There's actually another improvement that could be done, and would also solve your issue: making the non-parameterized version also provide a ``..``
to access the parent folder. But it gets pretty hard to read:
Textfile.``..``.``..``.misc.``foobar.txt``
Released in v0.4 as EnsureExists
.
In the current implementation of
TextFile
,DefaultValue
is used for theText
member if the file specified inPath
does not exist. IfDefaultValue
is not specified, it will be an empty string.If the contents of the file should always be used, but a non-existent file path is specified (for example, due to a mistake in the file path, a change in the file name, or a difference in the build environment), empty string is used as
DefaultValue
and no error occurs. This can cause unexpected bugs.I think there is a way, for example, to add a
bool
type parameter namedUseDefaultValue
and raise an exception if the file is not found and this parameter isfalse
.