I have directory say C:\d1. It has a file say f1.
I have to move this file to a sub directory under c:\d1. i.e., I have to
move f1 into C:\d1\d2.

I use fileSystemInfo.move for this but I get an error as follows -
{"The process cannot access the file because it is being used by another
process."}

how do I move.
I tried to copy the file and then delete...same problem.

any solutions?

Re: Move Files by Bob

Bob
Wed Apr 05 12:32:09 CDT 2006

If the file really is in use then you have to close the file and hence
remove the file lock.

I don't believe there's much else you can do.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"P K" <PK@discussions.microsoft.com> wrote in message
news:CE1EC50B-887B-47EB-A0A0-24CC075CFE20@microsoft.com...
>I have directory say C:\d1. It has a file say f1.
> I have to move this file to a sub directory under c:\d1. i.e., I have to
> move f1 into C:\d1\d2.
>
> I use fileSystemInfo.move for this but I get an error as follows -
> {"The process cannot access the file because it is being used by another
> process."}
>
> how do I move.
> I tried to copy the file and then delete...same problem.
>
> any solutions?
>
>



Re: Move Files by PK

PK
Wed Apr 05 15:58:02 CDT 2006

I cannot close the file cos I never opened it.
Most of these files were processed earlier to calling this function, but
looks like when this function is called they still are in memory.

Check the code below -

Public Shared Sub MoveFiles(ByVal path As String, ByVal pattern As String)
Dim File As System.IO.FileInfo
Dim FileNames As New ArrayList
Dim FileName As String

Dim Directory As New System.IO.DirectoryInfo(path)
For Each File In Directory.GetFiles(pattern)
FileNames.Add(File.FullName)
Next
File = Nothing
Directory = Nothing

For Each obj As String In FileNames
FileName = obj.Substring(obj.LastIndexOf("\") + 1, (obj.Length -
1 - obj.LastIndexOf("\")))
Try
System.IO.File.Move(obj, "c:\loaded\" & FileName)

'System.IO.File.Delete(obj)
Catch E As Exception
' File.
End Try

Next

End Sub


"Bob Powell [MVP]" wrote:

> If the file really is in use then you have to close the file and hence
> remove the file lock.
>
> I don't believe there's much else you can do.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consulting
> http://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
> "P K" <PK@discussions.microsoft.com> wrote in message
> news:CE1EC50B-887B-47EB-A0A0-24CC075CFE20@microsoft.com...
> >I have directory say C:\d1. It has a file say f1.
> > I have to move this file to a sub directory under c:\d1. i.e., I have to
> > move f1 into C:\d1\d2.
> >
> > I use fileSystemInfo.move for this but I get an error as follows -
> > {"The process cannot access the file because it is being used by another
> > process."}
> >
> > how do I move.
> > I tried to copy the file and then delete...same problem.
> >
> > any solutions?
> >
> >
>
>
>