N
ngposter
Try the following code snippet:
Directory.CreateDirectory(@"C:\Folder1\");
Directory.Move(@"C:\Folder1\", @"C:\Folder2\");
Directory.Delete(@"C:\Folder2\");
After executing, a C:\Folder1 still exists!
Stranger yet, place a breakpoint on "Directory.Delete(@"C:\Folder2\");" and
run the code. Have Windows Explorer open in the background.
At the breakpoint, you will see that (1) Folder1 is deleted and (2) Folder2
exists.
Now step through the "Directory.Delete(@"C:\Folder2\");" line.
Folder2 is deleted, but somehow Folder1 comes back!
The problem has to do with the closing backslash in the target parameter of
the .Move function.
The following will work as expected.
Directory.Move(@"C:\Folder1\", @"C:\Folder2");
Can someone confirm the same behavior?
If this is the case, I'd like to know: Is it bad practice to use a closing
backslash to differentiate folder paths from file paths?
Thanks.
btw: I have version 1.1.4322 of the framework.
Directory.CreateDirectory(@"C:\Folder1\");
Directory.Move(@"C:\Folder1\", @"C:\Folder2\");
Directory.Delete(@"C:\Folder2\");
After executing, a C:\Folder1 still exists!
Stranger yet, place a breakpoint on "Directory.Delete(@"C:\Folder2\");" and
run the code. Have Windows Explorer open in the background.
At the breakpoint, you will see that (1) Folder1 is deleted and (2) Folder2
exists.
Now step through the "Directory.Delete(@"C:\Folder2\");" line.
Folder2 is deleted, but somehow Folder1 comes back!
The problem has to do with the closing backslash in the target parameter of
the .Move function.
The following will work as expected.
Directory.Move(@"C:\Folder1\", @"C:\Folder2");
Can someone confirm the same behavior?
If this is the case, I'd like to know: Is it bad practice to use a closing
backslash to differentiate folder paths from file paths?
Thanks.
btw: I have version 1.1.4322 of the framework.