Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vbs move specific folders to specific locations

Posted on 2011-09-12
5
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 57

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 57

Accepted Solution

by:
Bill Prew earned 2000 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 57

Expert Comment

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

~bp
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

718 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