Showing posts with label File System. Show all posts
Showing posts with label File System. Show all posts

Thursday, September 27, 2007

VBScript to move files according to date

'Script Start

' Covet - Use this script carefully.


Const OverwriteExisting = True

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(" Your source folder - HERE - full path ")



For Each file In f.Files

if DateDiff("m",file.DateCreated, "09/01/2007") = 0 then 'change date accordingly

FSO.CopyFile file.path , " Destination folder with full path and \ at end - HERE " , OverwriteExisting
file.delete

End if


Next



For Each subf In f.subfolders

For Each file In subf.Files

if DateDiff("m",file.DateCreated, "09/01/2007") = 0 then 'change date accordingly

FSO.CopyFile file.path , " Destination folder with full path and \ at end - HERE " , OverwriteExisting
file.delete
End if


Next

Next

wscript.echo "End"





'Script End



How to execute a VBScript

VBScript to find file information

'Script Start


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\")
For Each file In f.Files
MsgBox file.Name
MsgBox file.DateCreated
MsgBox file.DateLastAccessed
MsgBox file.DateLastModified
MsgBox file.Path
MsgBox file.ShortName
MsgBox file.ShortPath
MsgBox file.Size
Next





'Script End



How to execute a VBScript

VBScript to get size of all subfolders in a directory

'Script Start


BaseDirectory = "D:\"

CheckFolder(BaseDirectory)

Function CheckFolder(Directory)
Set sss = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Directory)
For each sf In f.subfolders
value = round(sf.Size/1048576,2)

wscript.echo sf.name & " " & Value & " Mb"

Next
End Function




'Script End



How to execute a VBScript

VBScript to Retrieve a file from an URL and save it to the Hard Disk

'Script Start


URL = "http://sitename/filename.txt"
saveTo = "C:\filename.txt"

Set Obj1 = CreateObject("MSXML2.ServerObj1")
Obj1.open "GET", URL, false
Obj1.send()
Set Obj2 = CreateObject("ADODB.Stream")
Obj2.Open
Obj2.Type = 1 'adTypeBinary
Obj2.Write Obj1.ResponseBody 'Give the XML string to the ADO Stream
Obj2.Position = 0 'Set the stream position to the start
Set FSO = Createobject("Scripting.FileSystemObject")
if fso.Fileexists(saveTo) then Fso.DeleteFile hdLocation
set FSO = Nothing
Obj2.SaveToFile saveTo
Obj2.Close
Set Obj2 = Nothing
Set Obj1 = Nothing




'Script End

Got from the site www.vittorio.tk

How to execute a VBScript