Copy folder contents using VBScript

Posted by LukeR on Stack Overflow See other posts from Stack Overflow or by LukeR
Published on 2009-08-26T10:58:44Z Indexed on 2010/04/26 9:23 UTC
Read the original article Hit count: 220

Filed under:

I am trying to copy the contents of certain folders to another folder using VBScript.

The goal is to enumerate a user's AD groups and then copy specific folder content based on those groups.

I have code, which is currently not working.

Dim Group,User,objFSO,objFolder,source,target,StrDomain

StrDomain = "domain.local"
FolderBase = "\\domain.local\netlogon\workgrps\icons"
Set net = CreateObject("wscript.network")
Struser = net.username
target = "\\fs1\users\"&net.username&"\Desktop\AppIcons\"

DispUserInWhichGroup()

Function DispUserInWhichGroup()

On Error Resume Next

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")

For Each Group In User.Groups

source = FolderBase & Group.name

Set objFolder = GetFolder(source)

For Each file in objFolder.Files
objFSO.CopyFile source &"\"& file.name, target&"\"&file.name
Next

Next

End Function

This has been cobbled together from various sources, and I'm sure most of it is right, I just can't get it working completely.

Any assistance would be great.

Cheers.

© Stack Overflow or respective owner

Related posts about vbscript