System.IO.DirectoryNotFoundException

B

Ben

Hi all,

I got the above error when I tried to run through some simple vb 2008
code in the CopyFolder line. I tried using the UNC path in the quotes
but that didn't help. Can you share some thoughts on this? Thanks,

Ben


Imports System
Imports System.IO
Imports Scripting

Module MyCode


Sub bh_CopyFMC_Files()
Dim oFolder As FileSystemObject

oFolder = New FileSystemObject
oFolder.FolderExists("C:\Source\folder1\)
oFolder.FolderExists("D:\Destination\folder1")
oFolder.CopyFolder("C:\Source\folder1\", "D:\Destination\", True)

MsgBox("Folder has been copied")

End Sub


End Module
 
J

Joe Cool

Hi all,

I got the above error when I tried to run through some simple vb 2008
code in the CopyFolder line.  I tried using the UNC path in the quotes
but that didn't help.  Can you share some thoughts on this?  Thanks,

Ben

Imports System
Imports System.IO
Imports Scripting

Module MyCode

     Sub bh_CopyFMC_Files()
         Dim oFolder As FileSystemObject

         oFolder = New FileSystemObject
         oFolder.FolderExists("C:\Source\folder1\)
         oFolder.FolderExists("D:\Destination\folder1")
         oFolder.CopyFolder("C:\Source\folder1\", "D:\Destination\", True)

         MsgBox("Folder has been copied")

     End Sub

End Module

Al the FolderExists method does is return true if it exists and false
if not. Just what were you expecting them to do?
 
B

Ben

Joe,
Al the FolderExists method does is return true if it exists and false
if not. Just what were you expecting them to do?

I wanted to copy folder1 from source to destination. I added the two
lines above that to check whether folder exists in the source and in the
destination.

In the copyfolder line I added the parameter "True" to overwrite it if
it exists in the destination.

All I am trying to do is copy a folder from source to destination. What
am I doing wrong?

Thanks in advance,

Ben
 
J

Joe Cool

Joe,

 > Al the FolderExists method does is return true if it exists and false
 > if not. Just what were you expecting them to do?

I wanted to copy folder1 from source to destination.  I added the two
lines above that to check whether folder exists in the source and in the
destination.

But just invoking the FolderExists method and not doing anything with
the return value is not really "checking to see if the folder exists
or not".
In the copyfolder line I added the parameter "True" to overwrite it if
it exists in the destination.

All I am trying to do is copy a folder from source to destination.  What
am I doing wrong?

According to the documentation, if the destination folder specified
ends with "\" like your code does then the CopyFolder method assumes
the folder already exists. You invoke the FolderExists method for the
destination folder but if that returns false, you need to create the
folder. You are not.
 
B

Ben

Joe,
According to the documentation, if the destination folder specified
ends with "\" like your code does then the CopyFolder method assumes
the folder already exists.

Thanks so much, that did the trick. But I am curious because, I did
have the "True" parameter, so that if it does exist, it should have
overwritten it any way, is that a correct statement?
But just invoking the FolderExists method and not doing anything with
the return value is not really "checking to see if the folder exists
or not".

You right again. I as just stepping through the code and wanted to see
if the code executed.


Thanks so much for your helpful input.

Ben
 
J

Joe Cool

Joe,

 > According to the documentation, if the destination folder specified
 > ends with "\" like your code does then the CopyFolder method assumes
 > the folder already exists.

Thanks so much, that did the trick.  But I am curious because, I did
have the "True" parameter, so that if it does exist, it should have
overwritten it any way, is that a correct statement?

I would assume that the second parameter to the CopyFolder is only
applicable if the destination folder does not end in "\".
 
B

Ben

Joe,

Thanks so much for your help today.

Ben

I would assume that the second parameter to the CopyFolder is only
applicable if the destination folder does not end in "\".
 

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