Folder rename error Vb .Net [Resolved]

Posted by Sakthi.Singaravel under VB.NET on 11/2/2012 | Points: 10 | Views : 1622 | Status : [Member] | Replies : 3
When i try to rename folder in VB .Net using,

Directory.Move(inputLoc, Inputfol)


I got below error.

The process cannot access the file because it is being used by another process.

How can i solve this...?

Regards,
Singaravel M



Responses

Posted by: Sakthi.Singaravel on: 2/25/2013 [Member] Silver | Points: 25

Up
0
Down

Resolved
sorry guys...
That input folder's one file in holding by another process...

First i release that, that it works fine...

Regards,
Singaravel M

Sakthi.Singaravel, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Perumal93 on: 11/2/2012 [Member] Starter | Points: 25

Up
0
Down
The error is about that the directory you are trying to move is using by some other process. Not actually the directory. The file(s) in the directory is using by the other process. That's why the error occured. Read the error clearly. You will be able to know what is the error clearly. You better try another directory to move. But the trying directory should not be processing by some other process.

Sakthi.Singaravel, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Seng2hs on: 11/5/2012 [Member] Starter | Points: 25

Up
0
Down
public static void MoveDirectory(string source, string target)
{
var stack = new Stack<Folders>();
stack.Push(new Folders(source, target));

while (stack.Count > 0)
{
var folders = stack.Pop();
Directory.CreateDirectory(folders.Target);
foreach (var file in Directory.GetFiles(folders.Source, "*.*"))
{
string targetFile = Path.Combine(folders.Target, Path.GetFileName(file));
if (File.Exists(targetFile)) File.Delete(targetFile);
File.Move(file, targetFile);
}

foreach (var folder in Directory.GetDirectories(folders.Source))
{
stack.Push(new Folders(folder, Path.Combine(folders.Target, Path.GetFileName(folder))));
}
}
Directory.Delete(source, true);
}

public class Folders
{
public string Source { get; private set; }
public string Target { get; private set; }

public Folders(string source, string target)
{
Source = source;
Target = target;
}
}

Reference take from the below link
http://stackoverflow.com/questions/2553008/directory-move-doesnt-work-file-already-exist

Sakthi.Singaravel, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response