• Build DOS copy to allow spaces in destination file (A2K)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Build DOS copy to allow spaces in destination file (A2K)

    Author
    Topic
    #367713

    I am prompting my user for a string that will be used as the destination name in a file copy, as indicated in the code below. This works fine if the user does not include any spaces in the new file name. If they do, they get the DOS error “The syntax of the command is incorrect.”. DOS requires surrounding quotes if there are spaces, ei: copy test.mdb “test number 2.mdb”

    I have been trying to edit a.WriteLine (“copy ” & strDBPath & ” ” & CurrentDBDir & NewDBName & “.MDB”) so it will enclose the CurrentDBDir & NewDBName & “.MDB” in quotes so DOS will accept it. I thought that I had handled a situation like this sucessfully in the past, but haven’t been able to conquer it this time.

    Thanks,

    Randy

    ””””””””””””””””””””””””””””””””””””””””’

    strMsg = "Enter IMP Database Name, without .MDB extension (EI: MAY01IMP)"
    NewDBName = InputBox(Prompt:=strMsg, Title:="Build IMP Database", XPos:=2000, YPos:=2000)
     
    If NewDBName = "" Then
       Exit Function
    End If
    
    DoCmd.Hourglass True
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(CurrentDBDir & "CopyDupsMDB.bat", True)
    
    a.WriteLine ("copy " & strDBPath & " " & CurrentDBDir & NewDBName & ".MDB")
    a.WriteLine BatchCommand
    a.Close
    Call Shell(CurrentDBDir & "CopyDupsMDB.bat", 1)
    DoCmd.Hourglass False

    ””””””””””””””””””””””””””””””””””””””””’

    Viewing 1 reply thread
    Author
    Replies
    • #574180

      FYI: I learned from GHUDSON at http://www.forumco.com/jmhare/ that I could use chr(34) rather than using quote marks which solved my problem.

      Thanks,

      Randy

    • #574572

      Hi Randy,

      Try using an API call instead of shelling the copy command – its more effeciant and a lot faster.

      The code is as follows:

      Private Declare Function MsoCopyFileW Lib “mso9.dll” Alias “#882” (ByVal stOld As Long, ByVal stNew As Long, ByVal fFailIfItsThere As Long) As Long

      Function FCopyFile(ByVal stOld As String, ByVal stNew As String, Optional fFailIfItsThere As Boolean = True) As Integer

      FCopyFile = (MsoCopyFileW(StrPtr(stOld), StrPtr(stNew), Abs(fFailIfItsThere)) 0)

      End Function

      And then where you create and run the batch file, you can say the following instead:

      bRetVal=FCopyFile(strDBPath,CurrentDBDir & NewDBName & “.MDB”)

      Hope this helps!

      James

    Viewing 1 reply thread
    Reply To: Build DOS copy to allow spaces in destination file (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: