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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello Guys, I am trying to creat

Status
Not open for further replies.

cparralesl

Programmer
Jan 27, 2002
118
NI
Hello Guys,

I am trying to create a vbs that help me to make a copy from a directory to another directory based on a files list which are stored into a third directory.

Can somebody help with this?

I will appreciate your help, Thanks.



Cesar Humberto Parrales
 
Set compFld = FSO.GetFolder("c:\compfld")

For Each aFile In comFld.Files
If FSO.FileExists("c:\srcfld\" & aFile.Name) Then
FSO.CopyFile aFile, "c:\destfld"
End If
Next

should do it
 
Thanks for your help, it is useful but I forgot to say that the source is in a drive (P:\); The compare is in another drive (K:\). The destination folder is in the P:\.

I ran the code you gave me after the changes I made and show up ans error message saying: Object Required: 'comFld'

I will appreciate your help. This is the code with the changes:

Set fso = CreateObject("Scripting.FileSystemObject")
Set compFld = fso.GetFolder("P:\Data8")
For Each aFile In comFld.Files
If fso.FileExists("K:\Data5\" & aFile.Name) Then
FSO.CopyFile aFile, "P:\Data9"
End If
Next


Thanks
 
Sorry,

I did not realize that the right object name is CompFile.

Thans a lot. It is working great.


[thumbsup]
 
Hello,

The Script Show a Run Time Error message saying: Permission denied.

I do not know what happen because I do not have rights problems to those drives, I mean, If I do the copy manually no errors restriction come up. It does not work even in my local drive C:\. Beside, I have some others Script Files running and these are fine. Is there something wrong in my code?

Can someone help me with this?

Here is my current code:

Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set compFld = ObjFso.GetFolder("M:\Sistema\Data5")
For Each aFile In compFld.Files
If fso.FileExists("N:\Sistema\Data8\" & aFile.Name) Then
ObjFso.CopyFile aFile, "M:\Sistema\Data6"
End If
Next


I will really appreciate help about this.


Cesar Humberto Parrales
Application Support
 
ObjFso.CopyFile aFile, "M:\Sistema\Data6\"

Jon Hawkins
 
Great!,

Thank you jonscott8 , it is working great now.

[2thumbsup]

Cesar Humberto Parrales
Application Support
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top