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

need help copying files from one folder to another

Status
Not open for further replies.

sm2605

Programmer
Nov 19, 2003
44
0
0
US
Hi, i wrote this code as below but i keep getting a file not found error. I know the file exists, but im assuming there is something wrong with the code. By the way i am trying to copy all the files from the temp folder located in a datadirectory to the source of the dataDirectory.

fileSysObject.CopyFile dataDirectory & "\Temp", dataDirectory, overwrite
 
Try usnig wild cards

fileSysObject.CopyFile dataDirectory & "\Temp\*.*", dataDirectory, overwrite
 
Do you need a second \ after Temp?


Have a great day!

j2consulting@yahoo.com
 
Yes

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Hi, thanks for your help, but it works the way you typed it but it doesnt work the ther way around if i want to copy datadirectory into temp folder. here is what i have:

fileSysObject.CopyFile dataDirectory, dataDirectory & "\OTPTemp\*.*", True
 
Whats wrong with the FileCopy function?

[blue]FileCopy[/blue] SourceFilePath, DestinationFilePath
 
The fact that it can't take a folder name as a parameter for the file source...
 
This means that the filcopy function cannot copy multiple files at the same time. In order to do that i have to use the filesystemobject...but thats where the error it comming up
 
FileCopy can only take a a filename (or path to a filename) as a value for SourceFilePath. If you try and feed it a folder (or a path to a folder) it won't work.
 
Then use the CopyFolder function of FSO


Public Function CopyDir(Source As String, Dest As String, OverWrite As Boolean)
'This function uses the Windows Scriptin
' g Host
'You must have the scripting engine inst
' alled to use this code.
Dim fso
'Create file system object
Set fso = CreateObject("Scripting.FileSystemObject")
'put windows scripting host to work
fso.CopyFolder Source, Dest, OverWrite

End Function
 
Yes, we know. I was responding to your query as to what was wrong with FileCopy in this scenario...
 
I misread the question when I saw CopyFile :p
You have to forgive me its 3:00AM
 
Im already using the filesysobject. Thats how i came up with the original question.

dim fileSysObject

Set fileSysObject = CreateObject("Scripting.FileSystemObject")

fileSysObject.CopyFile dataDirectory, dataDirectory & "\OTPTemp\*.*", True


i cant use CopyFlder because i want the files within the folder to be copied

thanks
 
It does copy the files within the folder, to an existing folder or a new subdirectory, try the code I posted!
 
Hey guys thanks for your help. ive figured it out. i put the *.* in the wrong place. Here is the correct way:

fileSysObject.CopyFile dataDirectory & "\*.*", dataDirectory & "\Temp\", True
 
by the way where are you located that its 3am?
 
sorry to bother you again, but i have another question regardig this copying function. I just realized that if a user is going to be using this then they will need to register the appropriate dll's inorder for the file sys object to give an error. Is there a way to maybe create a function to copy each file using "copyFile" function and just call the function whenever i need it? If so how do i start.

by the way if this is considered another thread please let me know and i will rewrite it.

thank you
 
If you use late binding then DLL registration is not an issue. I believe ScrRun.dll is part of the standard install. Worst case scenario, you could iterate using the DIR function if you got an FSO error.

Good LucK!

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top