Please read the entire post as the entire post is relevant.
I wrote this C# code:
static void DumpDir(string dir)
{
string[] subdirs = Directory.GetDirectories(dir);
foreach (string subdir in subdirs)
{
DumpDir(subdir);
}
string[] files = Directory.GetFiles(dir);
}
static void Main(string[] args)
{
string startdir = @"G:\multimedia_dump";
dirindexstart = startdir.Split('\\').Length;
string[] dirs = Directory.GetDirectories(startdir);
foreach (string dir in dirs)
{
DumpDir(dir);
}
}
It opens a hard-coded directory, and loops through all of its subdirectories recursively. That’s all it does. That’s it.
However, it errors on a particular folder:
Notice how this is not the initial directory. Notice how, if you follow the code, it must logically be derived from one of the Directory.GetDirectories() calls. This folder name was not poorly generated. It’s real.
Not only is it real, but I can navigate to it in Explorer’s GUI:
Oddly enough, if you navigate to the folder in CMD, it’ll show up in DIR, but if you TAB until you get a suggestion for the folder name, it will not let you CD into it. I’d post a third link, but this thing won’t let me because I’m new.
What gives? I think the software that generated this folder did so using a low-level NTFS call of some kind. Is there a way to programatically sanitize these folder names, or work around this error so you can access folders that exist but shouldn’t?
It looks like your path contains a
|. This is an illegal character, as far as the normal Win32 APIs are concerned, but not as far as the NT APIs are concerned.You can disable some Win32 path limitations(for example the maximal path length of ~260 chars) by prefixing the path with
\\?\, but it looks like this doesn’t include|.So you probably need to drop down to the NT APIs to deal with this.