• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1188
  • Last Modified:

VBS script to copy, move, and then delete folders based on age

Experts,
I am looking for a VB script that I can use to copy folders from one server to another, and then delete the folders from there original location based on the folders age. I've been looking around the web and am getting a bit lost. Does anyone have some code they can share with a beginner?

Thanks,
0
fyrfyter
Asked:
fyrfyter
1 Solution
 
BadotzCommented:
Use the FileSystemObject. It is designed specifically for this type of activity.
0
 
elissaqpCommented:
This is a script to retrieve all porperties from a folder:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService. _
    ExecQuery("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    Wscript.Echo "Archive: " & objFolder.Archive
    Wscript.Echo "Caption: " & objFolder.Caption
    Wscript.Echo "Compressed: " & objFolder.Compressed
    Wscript.Echo "Compression method: " & objFolder.CompressionMethod
    Wscript.Echo "Creation date: " & objFolder.CreationDate
    Wscript.Echo "Encrypted: " & objFolder.Encrypted
    Wscript.Echo "Encryption method: " & objFolder.EncryptionMethod
    Wscript.Echo "Hidden: " & objFolder.Hidden
    Wscript.Echo "In use count: " & objFolder.InUseCount
    Wscript.Echo "Last accessed: " & objFolder.LastAccessed
    Wscript.Echo "Last modified: " & objFolder.LastModified
    Wscript.Echo "Name: " & objFolder.Name
    Wscript.Echo "Path: " & objFolder.Path
    Wscript.Echo "Readable: " & objFolder.Readable
    Wscript.Echo "System: " & objFolder.System
    Wscript.Echo "Writeable: " & objFolder.Writeable
Next


And this is for moving it:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults = objFolder.Rename("C:\Admins\Documents\Archive\VBScript")
    Wscript.Echo errResults
Next
0
 
fyrfyterAuthor Commented:
Thanks elissaqp. I think this is what I was looking for. Any tips for running it as a scheduled task?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now