file copy questions

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

....hope this question is on the right ng.

The code below works to copy all files and folders from D:\Template to a new
location that is specified by the user.
Is there any easy way to modify this code to copy everything except for one
or two child folders inside of D:\Template ?
....or would I have to copy everything and then delete the folders I don't
want copied over? (in other words, I want to copy everything but
D:\template\folder1 and D:\template\folder2 ) ...and I won't know all
file and folder name within D:\Template in advance, so I can't simply list
each specifically, but I will know the names of the folders that I don't
want copied.

thanks
Jeff

Dim fso

Dim sourcefolder As String, destinationfolder As String

sourcefolder = "D:\Template"

destinationfolder = "D:\" & LbDbNames.SelectedItem

fso = CreateObject("Scripting.FileSystemObject")

fso.CopyFolder(sourcefolder, destinationfolder)
 
...hope this question is on the right ng.

The code below works to copy all files and folders from D:\Template to
a new location that is specified by the user.
Is there any easy way to modify this code to copy everything except
for one or two child folders inside of D:\Template ?

Nope, unfortunately .NET's file copy doensn't have the ability to include
exclusions
...or would I have to copy everything and then delete the folders I
don't want copied over? (in other words, I want to copy everything but
D:\template\folder1 and D:\template\folder2 ) ...and I won't know
all file and folder name within D:\Template in advance, so I can't
simply list each specifically, but I will know the names of the
folders that I don't want copied.

Or you can loop through all the folders and only copy valid folders over.
 
...hope this question is on the right ng.

The code below works to copy all files and folders from D:\Template to a new
location that is specified by the user.
Is there any easy way to modify this code to copy everything except for one
or two child folders inside of D:\Template ?
...or would I have to copy everything and then delete the folders I don't
want copied over? (in other words, I want to copy everything but
D:\template\folder1 and D:\template\folder2 ) ...and I won't know all
file and folder name within D:\Template in advance, so I can't simply list
each specifically, but I will know the names of the folders that I don't
want copied.

thanks
Jeff

Dim fso

Dim sourcefolder As String, destinationfolder As String

sourcefolder = "D:\Template"

destinationfolder = "D:\" & LbDbNames.SelectedItem

fso = CreateObject("Scripting.FileSystemObject")

fso.CopyFolder(sourcefolder, destinationfolder)

Single codeline can copy files:
My.Computer.FileSystem.CopyFile(<source>, <destination>)

And delete unwanted files as Cor replied:
My.Computer.FileSystem.Deletefile(<path>)

Hope this helps...
 
Back
Top