Solved

vbs move specific folders to specific locations

Posted on 2011-09-12
5
189 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 53

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 53

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 53

Expert Comment

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

~bp
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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

8 Experts available now in Live!

Get 1:1 Help Now