Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey Fellas,
I am Stuck at another corner. I have pdf files in one folder and same files in second folder. When i add new files to folder one and run a script to copy all the files over to second folder. it should overwrite the existing files in second folder and copy the newly added files to the third folder. Any idea how to do that. Thankyou in advance for your help.
This is what i have so far..
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")With CreateObject("Scripting.FileSystemObject")
For Each file In .GetFolder("C:\Documents and Settings\gbaidwan\Desktop\new\").FilesobjFSO.CopyFile "C:\Documents and Settings\gbaidwan\Desktop\new\*.pdf" , "C:\Documents and Settings\gbaidwan\Desktop\new1\", TRUE
name = Left(.GetBaseName(file),7) & "." & .GetExtensionName(file)
If name <> file.Name Then
If Not .FileExists("C:\Documents and Settings\gbaidwan\Desktop\new\" & name) Then
file.Delete
Else
file.Name = name
End If
End If
Next 'file
End With

Const DeleteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")objFSO.CopyFile "C:\Documents and Settings\gbaidwan\Desktop\new\*.pdf" , "C:\Documents and Settings\gbaidwan\Desktop\new1\", TRUE
would this work with some modification? its giving me error right now

I'm not sure what you want here. You want to take all the PDF's in one folder, copy to a second folder, and make another copy in a third folder, while disregarding whatever was in the second and third folder?

No
I wanna copy files from one folder to second and if the files already exist in the second folder then delete both files.
For example:
Folder one has: 4 files
a.pdf
b.pdf
c.pdf
d.pdfand Second folder has: 3 files
a.pdf
b.pdf
c.pdfwhen the copy and delete script is run
Second Folder should be left with only one file:
d.pdf
because it didn't copy the existing files to second folder. Does that help you understand it better?
Thanks,

So if the file exists in both folders, delete both copies, otherwise copy from the first folder to the second?

Given the choice, this is something I'd do in a batch file; file structure manipulation is one thing it does well.
Untested VBScript:
Const sourceDir = "c:\folder one\" Const destDir = "C:\folder two\" With CreateObject("Scripting.FileSystemObject") For Each file In .GetFolder(sourceDir).Files If LCase(.GetExtensionName(file)) = "pdf" Then If .FileExists(destDir & file.Name) Then .DeleteFile destDir & file.Name file.Delete Else file.Copy destDir End If End If Next 'file End With

As always i really appreciate your help. The script is giving me an error though
Error: Object doesn't support this property or method: 'Copy'
in this line
.Copy destDir
Thanks,

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |