Google Answers Logo
View Question
 
Q: WSH / VB Script needed to do simple file copy ( No Answer,   3 Comments )
Question  
Subject: WSH / VB Script needed to do simple file copy
Category: Computers > Programming
Asked by: jadynsdad-ga
List Price: $5.00
Posted: 25 Jun 2003 16:30 PDT
Expires: 25 Jul 2003 16:30 PDT
Question ID: 221766
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.
Answer  
There is no answer at this time.

Comments  
Subject: Re: WSH / VB Script needed to do simple file copy
From: virdi-ga on 30 Jun 2003 05:50 PDT
 
a very very basic script, that just srung up in my mind as i was
reading through your q,

Dim fso as FileSystemObject
fso.copyfolder "F:\*" "D:\temp"

this is just very basic and may not do all the things that u want, but
it recursively copies all files and folders from F:\ drive to D:\temp.
I have not put in any error handling or any of the features that u
want. Will add them shortly.
Brings me the memory of good old days when Batch files were good :)
Subject: Re: WSH / VB Script needed to do simple file copy
From: virdi-ga on 02 Jul 2003 02:38 PDT
 
so much for creating a folder name by the date. use this
a = datepart("d",now)
b = monthname(datepart("m",now),true)
c = datepart("yyyy",now)
d = a&b&c
dim FSO
set fso = Createobject("Scripting.FileSystemObject")
if NOT(fso.folderexists("D:\temp\"&d)) then
	fso.CreateFolder("D:\temp\"&d)
end if

will post the whole script soon :)
Subject: Re: WSH / VB Script needed to do simple file copy
From: virdi-ga on 04 Jul 2003 00:16 PDT
 
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

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy