Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overwrite and dont overwrite

Status
Not open for further replies.

JohnJaak

Vendor
May 25, 2006
2
NL
Hello, i was writing an simple script. Its aim is to copy content of a folder to one another. In my case i have a message box asking to copy files. Then if the user select yes, then all content of folder1 will be copied and overwriten to folder2. This is working. But i am having trouble at the second option. I want to copy only the new files from folder1 to folder2 and also use the option to not overwrite files. At the second option it is "still" overwriting files. My code as shown below:






'info

dim objFso
dim objFilename1, objFilename2
dim strMember1, strMember2
dim strString1, strString2
dim rest
dim location, AnsweR

Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
Set objFilename1 = objFso.GetFolder("C:\folder1")
Set objFilename2 = objFso.GetFolder("C:\folder2")

location = "C:\folder1"

For Each strMember1 in objFileName1.Files
strString1 = strString1 & strMember1.name & vbCrLf
Next

For Each strMember2 in objFileName2.Files
strString2 = strString2 & strMember2.name & vbCrLf
Next

AnsweR = MsgBox("Back-up van uw homedirectory maken?",4,"good")

If strMember2 = srtMember1 Then
objFso.CopyFolder "C:\folder1", "C:\folder2", "True"
End if


If strMember2 <> srtMember1 Then
rest = strString1 - strString2
objFso.CopyFolder rest, location, "False"
End if
 
[tt]
AnsweR = MsgBox("Back-up van uw homedirectory maken?",4,"good")

if AnsweR=vbYes then
objFso.CopyFolder "C:\folder1", "C:\folder2", True
else 'being =vbNo
objFso.CopyFolder "C:\folder1", "C:\folder2", False
end if
[/tt]
The construction comparing strMember2 and strMember1 and strString1 - strString2 are really not making a lot of sense. Besides you should read the documentation on copyfolder to make sure you understand what you are doing is what you want.
 
I have read that section. Now i have made a new code. Still i have 1 error left saying "Acess denied". My code is as follows:



'Copy.vbs

Dim objFso, strInputFile, strDisplayString, File, objFolder,colFiles, location

set objFso = WScript.CreateObject("Scripting.FileSystemObject")

Set strInputFile = objFso.GetFile("C:\test\gg.txt")

location = "C:\test1"



If objFso.FolderExists("C:\test") Then
Set objFolder = objFso.GetFolder("C:\test")
Set colFiles = objFolder.Files
end if


For Each File in colFiles
If File.DateCreated <> File.DateLastModified then
objFso.CopyFile File, location, True
end if
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top