locked
VBS Script help needed RRS feed

  • Question

  • I have slightly complicated problem that I need help resolving, I apologies if it sounds like a school project.

    Enviroment details
    Windows server 2003 R2 domain
    Approx 50Windows XP laptops and 3 Windows Vista Laptops 

    Problem that needs resolving
    We have 53 laptops which have a folder for our templates stored in the root of c:\, however there is no standard folder name. They vary between BS templates, Templates and Work templates. Our Microsoft Office applications are set to look at these folders for the company templates.
    What I need to do is replace the all of the templates within that folder with new ones from a share but keeping the folder name the same..

    I have an idea of what I would like the VBS script to do but unfortunatly lack the knowledge to write it. Basically my big idea was to have a script which looks in the C:\ drive of the laptops for a folder with the variable "templates" deletes the content of the folder then copies the content from a share \\server\templates in to that directory.

    Once again I know it sounds like a school project but appreciate any help you guys can give me.
    • Edited by zalewskim Friday, November 27, 2009 4:08 PM typo
    Friday, November 27, 2009 4:06 PM

Answers

  • Hi - something like this should do it:

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TemplateFolder = FSO.GetFolder("C:\")

    For Each aFolder in TemplateFolder.SubFolders

      If Instr(LCase(aFolder.Name), "template") <> 0 Then

         FSO.DeleteFile "C:\" & aFolder.Name & "\*.*" 
         FSO.CopyFile  "\\yourserver\yourshare\templates\*.*", "C:\" & aFolder.Name
         Exit For

      End If

    Next

    Change the names/paths to match what you need

    Saturday, November 28, 2009 1:46 AM

All replies

  • Hi - something like this should do it:

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TemplateFolder = FSO.GetFolder("C:\")

    For Each aFolder in TemplateFolder.SubFolders

      If Instr(LCase(aFolder.Name), "template") <> 0 Then

         FSO.DeleteFile "C:\" & aFolder.Name & "\*.*" 
         FSO.CopyFile  "\\yourserver\yourshare\templates\*.*", "C:\" & aFolder.Name
         Exit For

      End If

    Next

    Change the names/paths to match what you need

    Saturday, November 28, 2009 1:46 AM
  • Thanks for responding so quickly to this!

    I have noticed one problem and that is that it only seems to copy the documents and not the folders within our template folder. Also could this script be amended to look for a folder that contains template and / or templates?

    Cheers
    Monday, November 30, 2009 9:05 AM
  • Hi, try this:

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TemplateFolder = FSO.GetFolder("C:\")

    For Each aFolder in TemplateFolder.SubFolders

      If Instr(LCase(aFolder.Name), "template") <> 0 Then

         FSO.DeleteFile "C:\" & aFolder.Name & "\*.*"
         FSO.CopyFolder  "\\yourserver\yourshare\templates", "C:\" & aFolder.Name
         Exit For

      End If

    Next

    This will now copy the contents of  \\yourserver\yourshare\templates, including sub-folders. The script will already work with any (actually, the first) folder it finds in the root of C: with "template" in the name, so this includes "templates".

    Monday, November 30, 2009 6:14 PM
  • Superb! that works a treat!

    Would there be any way that I can make this script run with elivated privilages without displaying the password?
    Tuesday, December 1, 2009 8:38 AM