Solved

vbs move specific folders to specific locations

Posted on 2011-09-12
5
187 Views
Last Modified: 2012-05-12
Thanks to some adml files, many of our users now have double desktop and and documents folders.
The policy problem is now fixed, but all the double folders created by the policy is still there, making it very hard for our users to understand where to put their files.
I need an automatic way to enumerate all files and folders in the "wrong" desktop and documents folders and move them to the right place and then delete the wrong desktop and documents folders, for every user.
The setup is as follows.
In "c:\private" share all the users folders are located.
Under these user folders they have a desktop and documents folder and the danish version of those called skrivebord and dokumenter.
What I´d like is a script that moves for example.:
C:\private\user1\skrivebord\*.*
to
C:\private\user1\desktop\*.*
then move
C:\private\user1\dokumenter\*.*
to
C:\private\user1\my documents\*.*
then delete
c:\private\user1\skrivebord
and
c:\private\user1\dokumenter

and then moves on to the next userfolder like "c:\private\user2" and do the same until everything is back in the right location.
Not all users have these double folders, only users that were logged on while the policy was still broken, so there has to be some kind of if exist in the script I guess.
It would be complete disaster if anything went wrong in this script, so I really hope someone can help me out here.
I have enough understanding of vbs to read a script and see what it does and edit existing scripts to do something similar, but I havent been able to find something that would be easily modified.

Thanks in advance;)
0
Comment
Question by:Ducknaldi
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Bill Prew
ID: 36522077
Is it correct to assume there could be subfolders under these folders, and that you would need to move those as well?

~bp
0
 
LVL 1

Author Comment

by:Ducknaldi
ID: 36522148
Yes, that would be correct
0
 
LVL 52

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36522412
Okay, I think this should do what you want.  Naturally due to the serious consequences of this script you will want to test it VERY thoroughly.  I did some basic testing but may not have tried every situation you may have there.

You may need to think about the possibility of the same file existing in bot the "bad" and the "good" folders.

sBaseDir = "c:\private"
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oUserFolder In oFSO.GetFolder(sBaseDir).SubFolders
   DoMove oUserFolder, "skrivebord", "desktop"
   DoMove oUserFolder, "dokumenter", "my documents"
Next

Sub DoMove(oFolder, sBad, sGood)
   If oFSO.FolderExists(oFolder.Path & "\" & sBad & "\") Then
      Wscript.Echo "Moving [" & oFolder.Path & "\" & sBad & "] to [" & oFolder.Path & "\" & sGood & "]"
      If Not oFSO.FolderExists(oFolder.Path & "\" & sGood & "\") Then oFSO.CreateFolder(oFolder.Path & "\" & sGood & "\")
      oFSO.CopyFile oFolder.Path & "\" & sBad & "\*.*", oFolder.Path & "\" & sGood & "\"
      oFSO.CopyFolder oFolder.Path & "\" & sBad & "\*.*", oFolder.Path & "\" & sGood & "\"
      oFSO.DeleteFolder oFolder.Path & "\" & sBad
   End If
End Sub

Open in new window

~bp
0
 
LVL 1

Author Closing Comment

by:Ducknaldi
ID: 36527738
Your solution was perfect.
I did some thorough testing and only needed to add "True" to the deletion line and everything worked perfect.
Thank you alot.
500P
;)
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 36528829
Great, glad that helped, thanks for the comments.

~bp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now