VB Script to move IE favorites.

I have redirected IE favorites using a custom Group Policy template for users ion a Terminal Server to a Users share on the network . Example \\servername\Users\%username%\Favorites
 I need a VB Script that will move the favorites themselves from the old location to the new location.
The old location would look something like the following.
C:\Documents and Settings\Username\ Favorites
This would have to be done for approximately 100 users

Thanks in advance,
Bret
ziplizzardAsked:
Who is Participating?
 
yehudahaConnect With a Mentor Commented:
try this:

and please notice you must put "\" at the end

strDest = "\\servername\Users\" & strUser & "\Favorites\"
Set objnet = CreateObject("WScript.Network")
Set objfso = CreateObject("Scripting.FileSystemObject")
strUser = objnet.UserName
strSource = "C:\Documents and Settings\" & strUser & "\Favorites"
strDest = "\\servername\Users\" & strUser & "\Favorites\"
 
Set objFolder = objFSO.GetFolder(strSource)
 
Set colFiles = objFolder.Files
 
For Each objFile in colFiles
        objFSO.MoveFile objFile.Path, strDest
Next

Open in new window

0
 
yehudahaCommented:
change the destination path in this line:

don't touch strUser

strDest = "\\servername\Users\" & strUser & "\Favorites"
Set objnet = CreateObject("WScript.Network")
Set objfso = CreateObject("Scripting.FileSystemObject")
strUser = objnet.UserName
strSource = "C:\Documents and Settings\" & strUser & "\Favorites"
strDest = "\\servername\Users\" & strUser & "\Favorites"
 
Set objFolder = objFSO.GetFolder(strSource)
 
Set colFiles = objFolder.Files
 
For Each objFile in colFiles
        objFSO.MoveFile objFile.Path, strDest
Next

Open in new window

0
 
ziplizzardAuthor Commented:
When the user runs this script they receive an error stating that the destination folder already exists. Because when the user logs in the Group Policy creates the new folder in the new location.
How can I move only the files?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
yehudahaCommented:
change this:
strDest = "\\servername\Users\" & strUser & "\Favorites"

to this:
strDest = "\\servername\Users\" & strUser & "\Favorites\"
0
 
yehudahaCommented:
notice to the "\" at the end
0
 
ziplizzardAuthor Commented:
Same error.
0
 
ziplizzardAuthor Commented:
A copy might work rather than a move, but how do you copy items in subfolders as well?
0
 
yehudahaCommented:
what is the exact error ?
0
 
ziplizzardAuthor Commented:
Error: File already Exists
error.jpg
0
 
ziplizzardAuthor Commented:
I am getting the same error.
0
 
ziplizzardAuthor Commented:
I think that by default Windows creates a sub folder in the favorites named "links" if this folder is there will it overwrite the existing file or ignore it by default? is it possible that this is causing the error?
0
 
yehudahaCommented:
becaue we moving the file each time and not copying it there is no overwrite issue here.

i tryed the the script without the "\" i got your error. when i put it at the end like i mention

it's work great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.