Solved

vbs move specific folders to specific locations

Posted on 2011-09-12
5
191 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 54

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 54

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 54

Expert Comment

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

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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