directory.getfiles help
in the photo is my project folder, i need to get all the files in the TestData folder, previously i used this code but if I run it on another machine it wont work as directory will be different
I want it to shorten the directory so it just points to the testdata folder within the project, how would i do this
8 Replies
Don't use an hardcoded and absolute path.
yes i know
ive seen people use
a short way just pointing to the folder in the project folder
how do i write that
Instead, build one dynamically, using
Path.GetFullPath(Path.Combine("..","..","..", Evironment.CurrentPath));
something like it.
Here's an example
ok thanks bro
a much better solution would be to set up
<CopyToOutputDirectory>
for the files you want copied, then just pass a relative path without any ..
this would make your program work fine even when published, and not just when running from inside visual studiowelll the easy answer is of course to just change that path.
oh doh scrolled up
there is also a method to get the special folder path, but Pobiega's answere is the right one
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
That's wrong, it does work if the structure is persistent, which in the case of testfiles is absolutely fine.
Besides that, the question was about paths, and knowing that there's a way to get the actual path by moving higher in hierarchy by using
..
is also legit.
I'm not saying it's the only solution, it's one of many, like always, it depends on the use-case.