Error trying to move file

  • Thread starter Thread starter Jeff Wilson
  • Start date Start date
J

Jeff Wilson

My VB call:
System.IO.File.Move("C:\CDRs\Suntera\Pending\080120040004.txt",
"C:\CDRs\Suntera\Loaded\")

Generates an exception:
'System.IO.IOException' occurred in mscorlib.dll
Additional information: Cannot create a file when that file already
exists.

However, that file does not already exist in the Loaded directory. In
fact, that directory is empty.

I know the solution to this is probably simple, but I can't figure it
out. Any ideas?

Thanks.
Jeff
 
That is because in the destination file name, you only have the directory
you want to put the file in. Not the full path of the new file (including
actual filename). It seems like you are assuming that the name of the
source file will be used, but the API is such that this doesn't have to be
the case.
 
Jeff,

* (e-mail address removed) (Jeff Wilson) scripsit:
My VB call:
System.IO.File.Move("C:\CDRs\Suntera\Pending\080120040004.txt",
"C:\CDRs\Suntera\Loaded\")

Generates an exception:
'System.IO.IOException' occurred in mscorlib.dll
Additional information: Cannot create a file when that file already
exists.

However, that file does not already exist in the Loaded directory. In
fact, that directory is empty.

Try something like that:

\\\
Dim FileName As String = "C:\foo\goo.txt"
System.IO.File.Move(FileName, System.IO.Path.Combine("C:\bar", System.IO.Path.GetFileName(FileName)))
///
 

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

Back
Top