I am trying to delete folders in a shared location on the network using C #. Some of the folder paths are too long to handle Windows. I tried several options for this. The best one is creating a FileSystemObject, adding \\? \ To the path, and calling DeleteFolder on the path that I want to delete, which works on my local computer for paths that are too long, because I have mapped drives like C: and G : etc., but when I try to use it in the network share folder, I get either HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND), or the value does not fall into the expected range.
Below is my code:
private static void DeletePathWithLongFileNames(string path)
{
string tmpPath = @"\\?\" + path;
FileSystemObject fso = new FileSystemObject();
fso.DeleteFolder(tmpPath, true);
}
let's say, for example, the shared folder + \\ myServer \ mySharedFolder \ folder1 \ etc \ etc, which will be the path string that I send to my delete function, then tmpPath displays as "\\\\\\\\\\ myServer \\ mySharedFolder \\ folder1 \\, etc. \\ etc.
I donβt know much about UNC, so I donβt know if this is wrong or not. I am pretty sure that something is wrong with my tmpPath variable, but again I'm not sure. Maybe this is a syntax error. But I cannot understand for life what is wrong. Thank you in advance
EDIT: I believe I found the answer, I'm testing it right now. So far this has worked for me. if I run the DeleteFolder method along the following path \\? \ UNC \ server \ sharedFolder \ folder1 \ etc \ etc ", this seems to work. Now I just need to figure out how to get rid of all the extra slashes.
EDIT 2: , . UNC.