Results 1 to 5 of 5

Thread: Copy command?

  1. #1
    Join Date
    Aug 2003
    Posts
    22

    Unanswered: Copy command?

    Hello,

    I don't want file2 to be overwritten if it already exsists. Is it possible with a command to check if the file exsists and return a true/false value or is there a better way to solve that problem?

    FileCopy file1, file2

    lowtek.

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    dim destSpec as string ' intended destination file
    destSpec = "c:\path\morepath\name.ext"
    if dir(destSpec) = "" then
    ' do your copy
    else
    ' file exists
    endif

    izy

  3. #3
    Join Date
    Aug 2003
    Posts
    22
    Originally posted by izyrider
    dim destSpec as string ' intended destination file
    destSpec = "c:\path\morepath\name.ext"
    if dir(destSpec) = "" then
    ' do your copy
    else
    ' file exists
    endif

    izy
    Didn't get it to work. It still overwrites existing file.

    Dim myPath As String
    Dim file1 As String
    Dim file2 As String
    Dim x
    Dim destSpec As String

    myPath = CurrentProject.Path & "\2a\"
    file1 = myPath & "_blank.doc"
    file2 = myPath & [2a2_manuf] & "-" & [2a1_databaseID] & ".doc"
    destSpec = file2

    If Dir(destSpec) = file2 Then
    x = Shell("winword """ & file2 & """", vbMaximizedFocus)
    Else

    FileCopy file1, file2
    x = Shell("winword """ & file2 & """", vbMaximizedFocus)
    End If

    lowtek.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i note you reversed the logic - maybe this takes you to a upper/lower case problem. ( "c" <> "C" etc). dir is case-independent but string comparison is not.

    go back to my original logic and test for "" ...you avoid the need to do case conversion:

    Dim myPath As String
    Dim file1 As String
    Dim file2 As String
    Dim x


    myPath = CurrentProject.Path & "\2a\"
    file1 = myPath & "_blank.doc"
    file2 = myPath & [2a2_manuf] & "-" & [2a1_databaseID] & ".doc"


    If Dir(file2) = "" Then 'file2 does not exist
    FileCopy file1, file2
    x = Shell("winword """ & file2 & """", vbMaximizedFocus)
    else
    x = Shell("winword """ & file2 & """", vbMaximizedFocus)
    End If

    izy

  5. #5
    Join Date
    Aug 2003
    Posts
    22
    Originally posted by izyrider
    i note you reversed the logic - maybe this takes you to a upper/lower case problem. ( "c" <> "C" etc). dir is case-independent but string comparison is not.

    go back to my original logic and test for "" ...you avoid the need to do case conversion:

    Dim myPath As String
    Dim file1 As String
    Dim file2 As String
    Dim x


    myPath = CurrentProject.Path & "\2a\"
    file1 = myPath & "_blank.doc"
    file2 = myPath & [2a2_manuf] & "-" & [2a1_databaseID] & ".doc"


    If Dir(file2) = "" Then 'file2 does not exist
    FileCopy file1, file2
    x = Shell("winword """ & file2 & """", vbMaximizedFocus)
    else
    x = Shell("winword """ & file2 & """", vbMaximizedFocus)
    End If

    izy
    Yeah, got it working.

    Thank you very much!

    lowtek.

Posting Permissions

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