Results 1 to 7 of 7

Thread: Just Move a directory, into an exsisting directory, replacing all files that exsist .

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Just Move a directory, into an exsisting directory, replacing all files that exsist .

    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?
    Wayne

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    check out the File System Object

  3. #3
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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".

  4. #4

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Originally posted by phinds
    check out the File System Object
    wheres the FSO?
    Wayne

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Just include a reference to "Microsoft Scripting Runtime"

  6. #6
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    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

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. strDest = "c:\Test"
    2.     strSource = "C:\Temp"
    3. '
    4. ' You should check here to make sure DEST and SOURCE actually exist - I dont bother!
    5. '
    6.     Set fso = CreateObject("Scripting.FileSystemObject")
    7.     Set fsoFolder = fso.GetFolder(strSource)
    8.     Set fsoFiles = fsoFolder.Files
    9.     For Each strFile In fsoFiles
    10.         strFileName = Mid(strFile, InStrRev(strFile, "\") + 1)
    11.         If Len(Dir(strDest & "\" & strFileName)) <> 0 Then
    12.             Kill (strDest & "\" & strFileName)
    13.         End If
    14.         FileCopy strSource & "\" & strFileName, strDest & "\" & strFileName
    15.     Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width