I'm trying to create a VBS that's supposed to iterate through a directory that has folders in it, these folders have files in them. The folders are named after users, I want to iterate through the user folders and copy the files in them to a another folder that is also named after the user. After copying the files to the destination, it should also delete the copied files from the first folder.
This is what I currently have:
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\Users\user\Desktop\folder")
Set fldrsub = fldr.SubFolders
For Each file In fldrsub
Set firstPath = file
myPath = Mid(firstPath,34,25)
RTrim(myPath)
WScript.Echo(myPath)
Set pathTwo = fso.GetFolder("C:\Users\user\Desktop\" & myPath & "\data\")
For Each oneFile In file.Files
WScript.Echo oneFile
oneFile.Copy(pathTwo)
Next
Next
It's supposed iterate through the folders, then trim the user name from the folder path, loop inside that folder and copy all the files to a destination based on the username.
I'm receiving an error "Permission Denied" (800A0046) that points to the oneFile.Copy(pathTwo)
command, I did research on it and found that the it could be caused by a permission issue or missing a backslash on a folder destionation. After checking out my permissions and checking the folder paths I still couldn't get it to work, though.