Copying Directorys-VBForums
Results 1 to 4 of 4

Thread: Copying Directorys

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    31

    Cool 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:
    1. My.Computer.FileSystem.CopyFile(foundFile, destPath & foundFile, True)
    2. Dim srcPath As String
    3.         Dim destPath As String
    4.         srcPath = ComboBox1.Text & "Web Browser"
    5.         destPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)
    6.        My.Computer.FileSystem.CopyDirectory(srcPath, destPath, True)
    7.  
    8. Dim srcPath As String
    9.         Dim destPath As String
    10.         srcPath = ComboBox1.Text & "Web Browser"
    11.         destPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)
    12.         ' set the current directory to the source
    13.         My.Computer.FileSystem.CurrentDirectory = srcPath
    14.         ' loop through the files in the directory
    15.         For Each foundFile As String In My.Computer.FileSystem.GetFiles _
    16.         (My.Computer.FileSystem.CurrentDirectory)
    17.             ' strip off the directory    
    18.             foundFile = Microsoft.VisualBasic.Right(foundFile, Len(foundFile) - 3)
    19.             ' check for .bmp extension    
    20.             If Microsoft.VisualBasic.Right(foundFile, 4) = ".bmp" Then
    21.                 ' copy the file        
    22.                 My.Computer.FileSystem.CopyFile(foundFile, destPath & foundFile, True)
    23.             End If
    24.         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.

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334

    Re: Copying Directorys

    Moved From The CodeBank And Added [highlight=vb.net]your code goes in here[/highlight] tags.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    7,906

    Re: Copying Directorys

    Isn't working isn't much help. A LOT more detail of the problems you are having is needed.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- SerialPort Answer

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein
    "They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety." Benjamin Franklin

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    31

    Cool 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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.