just copy paste the code and change the values of variable source and
destination, save the file with name xtn .vbs and try to run it. This
should do the basic thing, but i still haven't made any check for
existense of destination folder and things like that. I think u can
plug in those urself. In case u need help, get back to me.
''''''''''''''''''''''''''''''''''''''''''''''''''
' VB script project to copy the contents of a folder one to fodler 2
' author virdi@softhome.net
' Revisions
' initial 4th July 2003: checks if folders are present, copy them and
same with files, no error check.
'
'
'Goal: To create a simple VB script to copy contents of specific
'folder from one drive to a specific destination folder on another
'drive. Launch from a desktop shortcut.
'Extra ($5 tip): Automatically create a desitination folder named
with
'the system date under a specific folder.
'Extra+ ($5 tip) : The source drive is a Compactflash reader.
'Automatically launch this script (i.e. autorun.inf) when a
'Compactflash card is inserted.
'Caveat: This could probably be solved with a good old batch file,
but
'because of my interest in VB / WSH, I would like to proceed down this
'path.
Sub createDatedFolder(destination)
dim fso
set fso = Createobject("Scripting.FileSystemObject")
'separate the parts of the system date
a = datepart("d",now)
b = monthname(datepart("m",now),true)
c = datepart("yyyy",now)
'reassemble them as this to get a filename
d = a&b&c
'if the folder doen't exist create it
if NOT(fso.folderexists(destination&"\\"&d)) then
fso.CreateFolder(destination&"\\"&d)
end if
end sub
'main program starts here
Dim fso,fldrs,subfldrs,fls
set fso = CreateObject("Scripting.FileSystemObject")
source = "D:\workspace\scripts\2"
destination = "D:\workspace\scripts\1"
'check if there are any folders in the source
set fldrs = fso.GetFolder(source)
set subfldrs = fldrs.Subfolders
' WScript.Echo subfldrs.count
' if the subfldrs count is > 0 i.e. there are folders
if subfldrs.count > 0 then
copyFolders source,destination
end if
'check if there are any files in the source
set fldrs = fso.GetFolder(source)
set fls = fldrs.Files ' if this count is > 0, there are files to be
moved.
' WScript.Echo fls.count
if fls.count > 0 then
copyFiles source,destination
end if
Sub copyFolders(source,destination)
Dim fso
set fso = CreateObject("Scripting.FileSystemObject")
fso.copyfolder source&"\*.*",destination&"\"
set fso = Nothing
end Sub
Sub copyFiles(source,destination)
Dim fso
set fso = CreateObject("Scripting.FileSystemObject")
fso.copyfile source&"\*.*",destination&"\"
set fso = Nothing
end Sub |