473,320 Members | 1,572 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,320 software developers and data experts.

Directory.move

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 subfolder btest which has subfolder ctest plus a single file.
( c:\atest\btest\ctest\test.txt )
c:\aatest is an empty folder.

If I drag atest to aatest, I will have c:\aatest\atest\btest\ctest\test.txt
But as noted using the function as below wont work.
So conceptually I am mixed up, how should I think about this function, Thanks !!!

try
{
string sorDir=@"c:\atest";
string desDir=@"c:\aatest";
if ((Directory.Exists(sorDir)==true) && (Directory.Exists(desDir)==true))
{
Directory.Move(sorDir,desDir);
}
}
catch ( Exception e )
{
Console.WriteLine("What now : " + e.Message);
}
Nov 15 '05 #1
3 8812
string desDir=@"c:\aatest";
should be
string desDir=@"c:\aatest\atest";
Please read the documentation on Directory.Move, especially the remark
paragraph.

Willy.
"andrew" <an******@acw.com> wrote in message
news:35**********************************@microsof t.com...
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 subfolder btest which has subfolder ctest plus a single file.
( c:\atest\btest\ctest\test.txt )
c:\aatest is an empty folder.

If I drag atest to aatest, I will have
c:\aatest\atest\btest\ctest\test.txt
But as noted using the function as below wont work.
So conceptually I am mixed up, how should I think about this function,
Thanks !!!

try
{
string sorDir=@"c:\atest";
string desDir=@"c:\aatest";
if ((Directory.Exists(sorDir)==true) && (Directory.Exists(desDir)==true))
{
Directory.Move(sorDir,desDir);
}
}
catch ( Exception e )
{
Console.WriteLine("What now : " + e.Message);
}

Nov 15 '05 #2

Hi andrewcw,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, when you use Directory.Move to move a directory
into an emtpy one, an error message: "Cannot create a file when that file
already exists. " generated.

================================================== ======
In Directory.move docuement, you will find that:
"This method throws an IOException if, for example, you try to move
c:\mydir to c:\public, and c:\public already exists. You must specify
"c:\\public\\mydir" as the destDirName parameter, or specify a new
directory name such as "c:\\newdir"."

So you should specify your destination directory's name in that empty
directory, for your situation, you should use:
string desDir=@"c:\aatest\atest";

================================================== ======
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3

Hi andrewcw,

Is your problem resovled?
If you still have any concern, please feel free to tell me.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4

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

Similar topics

6
by: Chad | last post by:
I am receiving the following two errors in the code below. Both are on Line 56. error C2039: 'CreateDirectoryA' : is not a member of 'System::IO::Directory' error C2660: 'CreateDirectoryA' :...
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? ...
2
by: ngposter | last post by:
Try the following code snippet: Directory.CreateDirectory(@"C:\Folder1\"); Directory.Move(@"C:\Folder1\", @"C:\Folder2\"); Directory.Delete(@"C:\Folder2\"); After executing, a C:\Folder1...
1
by: rv | last post by:
I am developing an ASP.NET website with C#, VS 2003 and Framework 1.1. For some reason every time I execute a Directory.Move command, the next command takes 10-20 seconds to execute. Has anyone...
1
by: jojobar | last post by:
I have noticed that the Directory.Move removes the session as soon as the next Response.Redirect is done. It also appears that .Net framework constantly monitors all the directories below the root...
3
by: Karel | last post by:
Hello, I have a VB.NET application where I want to move directories over a network. I tried this with system.io.directory.move, but that doesn't work over different volumes. Has anyone a...
3
by: Daves | last post by:
why the heck can't I use Directory.Move() to rename a directory (containing files) to a entry 2 levels below e.g. uploads/tempfiles -> uploads/tempfiles/48/003files if I do this in one line...
4
by: Janiek Buysrogge | last post by:
Hello, Maybe this has been covered in the past in this group, but I wasn't able to find any references. If it has been covered, please provide me with a link of some sort. I'm trying to...
0
by: Matt MacDonald | last post by:
Hi all, I'm having a really frustrating problem. I have a web application that needs to modify the directory structure of the underlying files. The problem I'm having is that after the system...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.