Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy folder to logged in user My Docs...

Status
Not open for further replies.

daphtpunk

IS-IT--Management
Aug 31, 2010
1
US
First of all, hello, & thanks for all of the helpful tips I've pick up here so far.

What I am trying to do is copy a folder (with all files & sub-directories) from the root of C:, to the currently logged in user's "my documents".

What I've found so far is a script that will copy a folder/file to ALL user profiles "my docs", with some exceptions. I can't seem to find the code I need to simply do this for the currently logged in user.

Here is that script;


Dim fso
Dim oFolder1, objFolder, oFolder
Dim path
Dim WSHShell
Dim colFolders
Dim sDocsAndSettings
Dim strComputer

strComputer = "."

Set WSHShell = CreateObject("WScript.Shell")
Set fso = createobject("Scripting.FileSystemObject")

'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDE
Set oFolder1 = fso.GetFolder("c:\Template")

'COPY FILES TO USER PROFILES
sDocsAndSettings = "C:\Documents and Settings"
Set colFolders = fso.GetFolder(sDocsAndSettings)

For Each oFolder In colFolders.SubFolders
Select Case LCase(oFolder.Name)
Case "admin", "administrator", "newuser", "all users", "default user.original", "localservice", "networkservice"
'LEAVE THE DEFAULT PROFILES ON THE MACHINE
Case Else
' Check for the path
If fso.FolderExists(sDocsAndSettings & oFolder.Name & "\Application Data") Then
'COPY FOLDER TO USER PROFILE
fso.CopyFolder oFolder1, sDocsAndSettings & oFolder.Name & "\Application Data\Microsoft\Templates" ,True
End If
End Select
Next

Set fso = Nothing
Set WSHShell = Nothing




I want this to be a locally run script that is invoked by the user.

Any help would be awesome. Thanks!
 
I prefer to use RoboCopy for the actual file copy, it is efficient and easy to script as well as free from Microsoft.

Code:
Set WshShell = CreateObject("wscript.Shell")
Source = "C:\Template"
Destination = WshShell.SpecialFolders("MyDocuments")
Set objExec = WshShell.Exec("CMD.EXE /C RoboCopy " & Source & " " & Destination & "\Template /S /E /XO /R:0 /W:0")
Do While oExec.Status = 0
     'sleep while files copy
     WScript.Sleep 100
Loop

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top