-
Apr 18th, 2010, 06:20 AM
#1
Thread Starter
Junior Member
Copying Directorys
Hi,
I want to include a function in my program that involves my copying files from my cd drive D:/ to my hard drive C:/.
The code I'm using is below but it isn't working. The first one came up with an error, and the second one didn't come up with an error but didn't copy the files, I've searched round the internet but can't find anything.
vb.net Code:
My.Computer.FileSystem.CopyFile(foundFile, destPath & foundFile, True)
Dim srcPath As String
Dim destPath As String
srcPath = ComboBox1.Text & "Web Browser"
destPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)
My.Computer.FileSystem.CopyDirectory(srcPath, destPath, True)
Dim srcPath As String
Dim destPath As String
srcPath = ComboBox1.Text & "Web Browser"
destPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)
' set the current directory to the source
My.Computer.FileSystem.CurrentDirectory = srcPath
' loop through the files in the directory
For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.CurrentDirectory)
' strip off the directory
foundFile = Microsoft.VisualBasic.Right(foundFile, Len(foundFile) - 3)
' check for .bmp extension
If Microsoft.VisualBasic.Right(foundFile, 4) = ".bmp" Then
' copy the file
My.Computer.FileSystem.CopyFile(foundFile, destPath & foundFile, True)
End If
Next
The combo box allows the user to select which drive the cd is in, incase you were wondering.
Can anyone help?
Thanks,
m1la
Last edited by m1la; Apr 18th, 2010 at 01:59 PM.
-
Apr 18th, 2010, 07:23 AM
#2
Re: Copying Directorys
Moved From The CodeBank And Added [highlight=vb.net]your code goes in here[/highlight] tags.
-
Apr 18th, 2010, 09:08 AM
#3
Re: Copying Directorys
Isn't working isn't much help. A LOT more detail of the problems you are having is needed.
-
Apr 18th, 2010, 02:03 PM
#4
Thread Starter
Junior Member
Re: Copying Directorys
The error for the first section of code is "IOException was unhandled" and the error was about the last line of text in the first piece of code:
"My.Computer.FileSystem.CopyDirectory(srcPath, destPath, True)"
I think it's because you can only use this code to copy directorys on C:\ to C:\.
Is there a way to get around it?
The second segment of code is another piece of code I tried, it didn't come up with a error but didn't copy the files.
Is there anything else you need to know?
Thanks,
m1la
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|