string directorypath = @"C:\Folder01\Subfolder01\Next_level_Down ";
DirectoryInfo mydirectoryinfo = new DirectoryInfo(directorypath);
When the above code is run mydirectoryinfo.FullName and FullPath will cut off the trailing white space at the end of the last folder in directorypath. This seems like a bug?
This will cause a crash when I run:
DirectoryInfo[] mysubdirectories = mydirectoryinfo.GetDirectories();
As it will throw an exception "could not find a part of the path..."
I have a bunch of old folders that I am sorting and collecting data on so I need to get the DirectoryInfo on them, but some of them have been saved with white space at the end of the folder name. Rather than do a separate pass to correct folder names (which could break other connections to these folders) I was hoping on being able to get DirectoryInfo to handle the white space at the end of the folder name. If that is possible?
I have a list of directories that I've entered into a .CSV file. The paths are read into a List before being looped through to instance DirectoryInfo and run my checks, so there is no way to add more formatting that might help. I am using .Net Framework 4.7.2
What also helps with such unorthodox path names not supported by the shell (see https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/file-folder-name-whitespace-characters) is prepending
\\?\:From the documentation: