Announcement

Collapse
No announcement yet.

help with script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with script

    I need a script to search a folder and subfolders for certain file extensions then move the folder and all it contents to another folder.I have a script that will find a certain extension and move it but I want the script to search the whole folder and any subfolders for that file extension and once it finds it then it will move the folder that contains that extension plus the extension.Here is what I have so far.

    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    Set colFiles = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='C:\data'} Where " _
            & "ResultClass = CIM_DataFile")
    
    For Each objFile in colFiles
        If objFile.Extension = "doc" Then
            strCopy = "D:\Officedata\" & objFile.FileName _
                & "." & objFile.Extension
            objFile.Copy(strCopy)
            objFile.Delete
        End If
        If objFile.Extension = "xls" Then
            strCopy = "D:\Officedata\" & objFile.FileName _
                & "." & objFile.Extension
            objFile.Copy(strCopy)
            objFile.Delete
        End If
    Next
    Last edited by Dumber; 16th September 2011, 16:16.
    MCITP: EA

    MCITP: SA

  • #2
    Re: help with script

    With Powershell you might end up something like this (untested)..

    $format =doc
    $Destination = C:\Destination
    $Source = C:\sourcefolder

    $Dir = get-childitem $Source -recurse
    $files = $Dir | where {$_.extension -eq "$format"}
    $files | move-item -destination $Destination

    Or use something like robocopy or so?
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Re: help with script

      Thanks for the suggestion, I found a solution last week but your suggestion involves alot less code so I might test your suggestion of powershell.
      MCITP: EA

      MCITP: SA

      Comment

      Working...
      X