File.move Exception error

P

PAPutzback

Message Exception: The process cannot access the file "K:\EDI
DATA\ANS\OUTBOUND\ARCHIVE\IPHC20041207.TXT" because it is being used by
another process.

StackTrace Exception: at System.IO.__Error.WinIOError(Int32
errorCode, String str)
at System.IO.File.Move(String sourceFileName, String destFileName)
at Scout.MyScoutService.ANSSendAll()

The Code:
For Each FiletoArchive In FilesToArchive.GetFiles("*.txt")
EventLog1.WriteEntry(FiletoArchive.FullName & " Fullname")
EventLog1.WriteEntry(FiletoArchive.Name & " Name")
File.Move(FiletoArchive.FullName, _
"K:\EDI DATA\ANS\OUTBOUND\ARCHIVE\" & FiletoArchive.Name)
Next

Is the problem with K being a network drive or the path having spaces
in the directory names?
Also this code is running as a service and I can't debug it without it
showing me assembly code.


Thanks,
Phillip Putzback
 
P

PAPutzback

So I changed it to use the fileinfo.moveto function and I get the same
error

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

I also change the service to run under my account with no change in the
results.

Phillip
 
P

PAPutzback

Dim FilesToArchive As DirectoryInfo = New DirectoryInfo("C:\working")
Dim FiletoArchive As FileInfo
Try
For Each FiletoArchive In
FilesToArchive.GetFiles("*.txt")
EventLog1.WriteEntry(FiletoArchive.FullName & "
Fullname")
EventLog1.WriteEntry(FiletoArchive.Name & " Name")

FiletoArchive.MoveTo("\\chefile5\APPs$\ProHealth\EDI
DATA\ANS\OUTBOUND\ARCHIVE\" _
& FiletoArchive.Name.Trim)
Next

For Each FiletoArchive In
FilesToArchive.GetFiles("*.gpg")
FiletoArchive.Delete()
Next

Catch ex As Exception
EventLog1.WriteEntry("Exceptions for the archive
process")
EventLog1.WriteEntry("Message Exception: " &
ex.Message.ToString)
EventLog1.WriteEntry("Source Exception: " &
ex.Source.ToString)
EventLog1.WriteEntry("StackTrace Exception: " &
ex.StackTrace.ToString)
End Try
 
M

Mike McIntyre

Here is some code that works to provide you a starting point for resolving your problem.

Dim sourceDirectoryInfo As DirectoryInfo = New DirectoryInfo("C:\FilesToMove")
Dim destinationDirectoryInfo As DirectoryInfo = New DirectoryInfo("C:\MovedFiles")
Dim typeFileInfo As FileInfo
For Each typeFileInfo In sourceDirectoryInfo.GetFiles("*.txt")
typeFileInfo.MoveTo(destinationDirectoryInfo.Name & typeFileInfo.Name)
Next
For Each typeFileInfo In sourceDirectoryInfo.GetFiles("*.gpg")
typeFileInfo.Delete()
Next

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top