How to check if a directory move had been finished

Posted on 2010-11-29
Last Modified: 2013-12-17

at a webside a user can create a temporary ID for a new document and file uploads.
When the user press Save at the app I do a callback to move the tempoary folder and the uploaded files to the right folder.
string tpath = GetNewId();
string spath = Session["TempId"];
Directory.Move(spath, tpath);

The matter is that the new directory (tpath) will be scanned some commands later and very often Directory.Move hasn't finished than and I get a exception.
So what I need is to wait until Directory.Move has finished all activity or a simular function that can do so.

How can I solve this problem?


Question by:andre72
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

abdkhlaif earned 250 total points
ID: 34230664

DirectoryInfo di = new DirectoryInfo(spath);
while (di.Exists)
Console.WriteLine("Folder moved");

Open in new window


Expert Comment

ID: 34230712
of course this code should be be placed after you call Directory.Move
LVL 20

Assisted Solution

BuggyCoder earned 250 total points
ID: 34232495
Other way of doing the same is using Asynchronous Delegate Callback using IAsyncCallback method.

public delegate void MyDelegate;

public class MyClass
private MyDelegate del;
public MyClass()
del=new MyDelegate(this.ValidateMove);

public void StartChecking()
del.BeginInvoke(null, new AsyncCallBack(MoveFinished),null);

private void MoveFinished()
//Move has been finished

private void ValidateMove()
DirectoryInfo di=new Directoryinfo("UrPath");


the above code allows you to asynchonously start waiting for move finished, and will call Move finished method after it is done.

Try reading about Asynchronous Delegates Callback.
Will give you more detail of what i am trying to do here.

hope it helps

Author Closing Comment

ID: 34318914

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question