Real'sHowTo AddThis Feed Button
Custom Search

Copy, delete or move a fileTag(s): WSH VBScript


' copy
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.CreateTextFile(".\output.dat", True)
aFile.WriteLine("1234")
Set aFile = fso.GetFile(".\output.dat")
aFile.Copy("./output.bak")

' alternate
fso.CopyFile "c:\mydir\*.*", "d:\backup\",TRUE

' copy folder
fso.CopyFolder "c:\mydir\*", "D:\backup\mydir\",TRUE

' delete
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.GetFile(".\output.dat")
aFile.Delete

' move or rename
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.CreateTextFile(".\output.dat", True)
aFile.WriteLine("1234")
Set aFile = fso.GetFile(".\output.dat")
aFile.Move ".\output.ok"

blog comments powered by Disqus


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2014
[ home ]