How to check if a directory move had been finished

Posted on 2010-11-29
Medium Priority
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 1000 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 1000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 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