The file is in use by another process after reading a directory

JB493
JB493 used Ask the Experts™
on
I am using the following code to find files in a directory and attach them to an email. It finds the file and attaches them as it is supposed to. when I try to then move them to a history folder I get the message "the file is in use by another process."  I have tried everything I can think of to release the resources but it doesn't seem to help.

For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments)
  Next
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
"It finds the file and attaches them as it is supposed to."

It's more likely that the attaching process is what's holding the file lock.  Is there a way to completely dispose of the mail object after you're done with it?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial