dcsimg
Results 1 to 2 of 2

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    1

    Copy files from one directory excluding a specific folder

    Hi guys, I'm trying to make a solution where I can copy over all files/folders from one directory to another but excluding a specific folder ("data"). Here's what I have so far

    Code:
    Dim Paths As New ArrayList
    Paths.AddRange(Directory.GetDirectories("C:\Users\path1\path2"))
    For Each Item As String In Paths
         If Not Item.ToString.Contains("\data\") Then
            My.Computer.FileSystem.CopyDirectory(Item, "D:\path1\path2\path3", True)
                End If
            Next
                
    Dim Files As New ArrayList
    Files.AddRange(Directory.GetFiles(("C:\Users\path1\path2"))
    For Each Item As String In Paths
        My.Computer.FileSystem.CopyFile(Item, "D:\path1\path2\path3", True)
    Next
    The theory behind this is to add all directories and folders to the array list, and if one of the items contains the data folder, then don't copy it. The result I'm getting is that it copies all the files within the folders of Directory1, and places them into Directory2 without excluding the data folder OR copying the root files in Directory1. Can anyone point out where I'm going wrong?
    Last edited by BobTarkish; Mar 8th, 2018 at 03:48 AM. Reason: Code indent format

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


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.