Reputation: 1
Right now my code uses the following to reference the folder which is in the same directory as my executable:
Directory.GetDirectories("Customers\\")
It seems to be working fine but I am worried about edge cases where something may go wrong. Is this something to worry about? Should I convert it to:
Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "Customers\\")
Upvotes: 0
Views: 419
Reputation: 1
After more research it appears it really depends on what my application is doing and if my "Environment.CurrentDirectory" is ever changed within the application.
In my case "Environment.CurrentDirectory" is changed when I use OpenFileDialog().
My choices are set FileDialog.RestoreDirectory to true which will restore the "Environment.CurrentDirectory" if it is changed within the dialog box or to prepend "AppDomain.CurrentDomain.BaseDirectory" to all my code that uses Directory.
From the documentation remarks (https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getdirectories?view=net-6.0): "The path parameter can specify relative or absolute path information, and is not case-sensitive. Relative path information is interpreted as relative to the current working directory."
So as long as your current working directory does not change you do not have to do absolute references. If it does you should use absolute or prevent your working directory from changing.
Upvotes: 0