943,925 Members | Top Members by Rank

Ad:
Jan 16th, 2007
0

Copy Folder with %Computername% and %Username% prefix

Expand Post »
Hi all,

It's been a long time since i was last logged in here. Comatose was probably glad to see the back of me and my non stop questioning ;-)

Well today i have a small question which i hope someone can help with...

Here is my question... im trying to copy a profile for the currently logged in user to specified location.

The location of the profile will presumable be,

"c:\documents and settings\" + %username%

and the destination will be,

x:\ProfileBackup\%computername%\%username%\

Here is what i thought ws right but isnt...
vb Syntax (Toggle Plain Text)
  1. ' /* Declare Variables */
  2.  
  3. Dim fso, src, dest
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5. src = "c:\documents and settings\%USERNAME%\"
  6. dest = "x:\ProfileBackup\%computername%\%username%\"
  7.  
  8. If fso.FolderExists (src) Then
  9. fso.CopyFolder (src), (dest)
  10. End If
  11.  
  12. If Not fso.FolderExists (dest) Then
  13. fso.CreateFolder (dest)
  14. End If
Ideally what i was trying to do (badly) was copy a users profile to a network drive to a folder named by the computername and userprofile so that there would be a different back up for each machine they logonto.

However!!!

This may prove troublesome depending on network speeds and profile size etc.. so i was also hoping someone could help and add into the script the ability to copy a single folder "Favorites" from here instead and rem it out. or the ability to copy 2 or 3 folders at a time rather than the entire profile ;-)

I hope someone can help

Thanks in advance.

Phreak ;-)
Last edited by WaltP; Jan 16th, 2007 at 2:29 pm. Reason: We have code tags to help make the code readable...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Phreak is offline Offline
43 posts
since Feb 2005
Jan 16th, 2007
0

Re: Copy Folder with %Computername% and %Username% prefix

Made a quick ammendment..... Still not right but better i think
vb Syntax (Toggle Plain Text)
  1. ' /* Declare Variables */
  2.  
  3. Dim fso, src, dest
  4. dim wsh
  5. set wsh = createobject("WScript.Shell")
  6. login_name = wsh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name")
  7.  
  8. src = "C:\documents and settings\" & login_name & "\Favorites"
  9. dest = "G:\ProfileBackup\%computername%\%username%\"
  10.  
  11. If fso.FolderExists "src" Then
  12. fso.CopyFolder "src", "Dest"
  13. End If
  14.  
  15. If Not fso.FolderExists "dest" Then
  16. fso.CreateFolder "dest"
  17. End If
Last edited by WaltP; Jan 16th, 2007 at 2:30 pm. Reason: Code tags added
Reputation Points: 10
Solved Threads: 0
Light Poster
Phreak is offline Offline
43 posts
since Feb 2005
Jan 16th, 2007
0

Re: Copy Folder with %Computername% and %Username% prefix

update......
vb Syntax (Toggle Plain Text)
  1. ' /* Declare Variables */
  2.  
  3. Dim fso, src, dest
  4. dim wsh
  5. Set fso = CreateObject("Scripting.FileSystemObject")
  6. set wsh = createobject("WScript.Shell")
  7. login_name = wsh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name")
  8.  
  9. src = "C:\documents and settings\" & login_name & "\Favorites"
  10. dest = "G:\ProfileBackup\%computername%\%username%\"
  11.  
  12. ' /* Check If "Dest" exists, if not, create it */
  13. if Not fso.FolderExists("dest") then
  14. fso.CreateFolder "dest"
  15. End If
  16.  
  17. fso.CopyFolder src,"dest", 1
Last edited by WaltP; Jan 16th, 2007 at 2:31 pm. Reason: Code tags added -- your turn
Reputation Points: 10
Solved Threads: 0
Light Poster
Phreak is offline Offline
43 posts
since Feb 2005
Jan 16th, 2007
0

Re: Copy Folder with %Computername% and %Username% prefix

Still not working but i cant see where im going wrong.. any ideas???
Reputation Points: 10
Solved Threads: 0
Light Poster
Phreak is offline Offline
43 posts
since Feb 2005
Jan 16th, 2007
0

Re: Copy Folder with %Computername% and %Username% prefix

Its working in my case....just made a slight modification:
visualbasic Syntax (Toggle Plain Text)
  1. fso.CopyFolder src, dest, 1

Removed the quotes around dest ....
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 10th, 2008
0

Re: Copy Folder with %Computername% and %Username% prefix

The script only copies one file to the destination.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
techkp is offline Offline
1 posts
since Dec 2008
Dec 29th, 2008
0

Re: Copy Folder with %Computername% and %Username% prefix

Click to Expand / Collapse  Quote originally posted by techkp ...
The script only copies one file to the destination.
Seriously... THIS THREAD was completed 2 YEARS ago !!!! the script works fine lol

2 Years... how did you not notice that?

:-)
Reputation Points: 10
Solved Threads: 0
Light Poster
Phreak is offline Offline
43 posts
since Feb 2005
Dec 29th, 2008
0

Re: Copy Folder with %Computername% and %Username% prefix

*Just Smiles*
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Fill textboxes from listbox selection from Access db
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Portability





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC