Copy folder contents using VBScript
I am trying to copy the contents of certain folders to another folder using VBScript.
The goal is to list custom user groups and then copy the contents of a specific folder based on those groups.
I have some code that 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 was cobbled together from various sources and I'm sure most of them are correct, I just can't get it to work completely.
Any help would be great.
Greetings.
+2
source to share
3 answers
The target folder must not exist, but it must be specified:
C: \ Z in C: \ A \ Z will work, but C: \ Z in C: \ A will not work.
The folder where the new folder will be located must exist:
C: \ A must exist, but C: \ A \ Z is optional.
Trailing slashes must be omitted:
C: \ Z to C: \ A \ Z will work, but C: \ Z \ to C: \ A \ Z \ will not work.
0
source to share