Solved

vbs move specific folders to specific locations

Posted on 2011-09-12
5
186 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 51

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 51

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 51

Expert Comment

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

~bp
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

18 Experts available now in Live!

Get 1:1 Help Now