inimicaljords
asked on
how to copy a directory and bypass errors VB 08
I am trying to make a small backup program in VB 2008 that copies a directory. I have researched for a long time and have posted a previous question with no suitable answer.
The problem I am running into is if I try to copy a directory and a file is in use or I have access denied it halts the copying progress at the file with the error and doesn't copy anything after it. I have explained this to many people but a lot of them can't understand the question so I am going to write an example:
say c:\test contains the following files:
a.txt
b.txt
c.txt
Say we do not have access permissions to b.txt
If i try to copy the directory using:
My.Computer.FileSystem.Cop yDirectory ("c:\test" , "c:\backup", True)
I will get an access denied error on b.txt and the copying process halts. I basically need the program to do something like this:
copydirectory c:\test
if file error Then
Skip file and continue copying
Easier Said then done. Please, do not focus on fixing the error by correcting permissions. That is not the solution I am looking for. I basically, want to skip any errors and continue copying until the directory and sub directories are copied.
If anyone has any suggesions, I would greatly appreciate it.
The problem I am running into is if I try to copy a directory and a file is in use or I have access denied it halts the copying progress at the file with the error and doesn't copy anything after it. I have explained this to many people but a lot of them can't understand the question so I am going to write an example:
say c:\test contains the following files:
a.txt
b.txt
c.txt
Say we do not have access permissions to b.txt
If i try to copy the directory using:
My.Computer.FileSystem.Cop
I will get an access denied error on b.txt and the copying process halts. I basically need the program to do something like this:
copydirectory c:\test
if file error Then
Skip file and continue copying
Easier Said then done. Please, do not focus on fixing the error by correcting permissions. That is not the solution I am looking for. I basically, want to skip any errors and continue copying until the directory and sub directories are copied.
If anyone has any suggesions, I would greatly appreciate it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Might use Process class to invoke XCopy. It has a lot more flexibility, and includes /C to continue copying after an error.
ASKER
this looks very promising but I am having a little problem.
CopyDirectory("c:\test", "c:\backup")
When I call the function I get an error:
DestinationDirectory.Creat e()
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I tried putting a msgbox in before the line code for debugging and I get an error on the msg box
MsgBox(DestinationDirector y)
Argument 'Prompt' cannot be converted to type 'String'
Seems like destinationdirectory and sourcedirectory can't convert DirectoryInfo into a string.
I extremely appreciate the help.
CopyDirectory("c:\test", "c:\backup")
When I call the function I get an error:
DestinationDirectory.Creat
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I tried putting a msgbox in before the line code for debugging and I get an error on the msg box
MsgBox(DestinationDirector
Argument 'Prompt' cannot be converted to type 'String'
Seems like destinationdirectory and sourcedirectory can't convert DirectoryInfo into a string.
I extremely appreciate the help.
ASKER
Thank you so much! I fixed the error I was having. It was with my part which was causing an infinite loop. Your code worked perfectly. I appreciate it more than you can imagine =)
Glad to help.