Just Move a directory, into an exsisting directory, replacing all files that exsist , if i am moving the directory to, and the file already exsists there,
Just like in Windows Explorer,
How do i do this?
Printable View
Just Move a directory, into an exsisting directory, replacing all files that exsist , if i am moving the directory to, and the file already exsists there,
Just like in Windows Explorer,
How do i do this?
check out the File System Object
You need some code that does:
For all Files in the Directory:
- If the File is in the target directory, delete it.
- Copy the File to the target Directory.
Loop until end of Directory.
Use the FSO for the "all files in directory".
wheres the FSO?Quote:
Originally posted by phinds
check out the File System Object
Just include a reference to "Microsoft Scripting Runtime"
as wpearsall said, you need a reference to the Scripting Runtime library, and then check out both the on-line help for FSO and also use the object browser to check out all the properties & methods
Taking the algorithm:
For all Files in the Directory:
- If the File is in the target directory, delete it.
- Copy the File to the target Directory.
Loop until end of Directory.
You might end up with something like:
VB Code:
strDest = "c:\Test" strSource = "C:\Temp" ' ' You should check here to make sure DEST and SOURCE actually exist - I dont bother! ' Set fso = CreateObject("Scripting.FileSystemObject") Set fsoFolder = fso.GetFolder(strSource) Set fsoFiles = fsoFolder.Files For Each strFile In fsoFiles strFileName = Mid(strFile, InStrRev(strFile, "\") + 1) If Len(Dir(strDest & "\" & strFileName)) <> 0 Then Kill (strDest & "\" & strFileName) End If FileCopy strSource & "\" & strFileName, strDest & "\" & strFileName Next