473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Directory.Move bug when using closing backslash?

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.
Nov 16 '05 #1
2 3535
"ngposter" <ng******@earthlink.net> wrote in message news:uq*************@TK2MSFTNGP09.phx.gbl...
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?


You can't have a folder and file of the same name so there is no need to differentiate. Generally I wouldn't use a trailing slash
because it would indicated to me the next level eg "C:\Folder1\" seems to indicate something in folder1, not folder1 itself.

--
Michael Culley
Nov 16 '05 #2
Hm,

Rather strange. As Michael said you do not normally deal with directories using trailing \, but using one shouldn't do any harm either. The problem is with Directory.Move which not only moves a directory, but also the contents, and having a trailing \ in the destination directory confuses it. However, I have no idea how or why it manages to recreate Folder1 after removing Folder2. It would be interesting if someone could shed any light on that.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Anand K Rayudu | last post by:
Hi all, I am trying to find a way to get the files recursively in a given directory, The following code is failing, can some one please suggest what could be problem here from os import...
2
by: Dave Johnston | last post by:
Hi, I'm currently trying to create a wrapper that uses C functions but behaves like ifstream (from fstream.h) - this is because the platform I'm using (WinCE) doesn't support streams and this is...
6
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? ...
3
by: andrew | last post by:
I do not understand how this function should work. It seems to be different than when I drag a folder ... error message: Cannot create a file when that file already exists. c:\atest has...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
15
by: Jameson | last post by:
Happy New Year, Everyone! I am trying to figure out how to display a bunch of images (mainly JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a local directory on the system....
0
by: Fabian Braennstroem | last post by:
Hi, I am using lfm, a curses based file manager, and want to change into the last directory of my lfm-session after closing it. To be more clear: 1) run lfm from console in the home directory...
25
by: Peter Michaux | last post by:
Hi, I'm thinking about code minimization. I can think of a few places where whitespace matters a + ++b a++ + b a - --b a-- -b when a line ends without a semi-colon in which case the new...
4
by: rdoneil | last post by:
I am in unix and in my perl program, I am trying to move back to the directory the program was originally started in. Obviously, at somepoint in my program it has to move to another directory, and...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.