Announcement

Collapse
No announcement yet.

FileCopy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    replied
    Have you tried using BYCOPY ? Solving that is one of it's prime uses...

    Code:
    #COMPILE EXE
    FUNCTION PBMAIN
        DIM a AS ASCIIZ * 1024
        a = "abc"
        CALL MyFunction(BYCOPY a)
    END FUNCTION
    
    FUNCTION MyFunction(b AS ASCIIZ) AS LONG
        MSGBOX b
    END FUNCTION
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Egbert Zijlema
    replied
    Originally posted by Semen Matusovski:
    Egbert --
    Could be you specify "Sema" only ?
    Semen,
    I'm ashamed! Indeed my program did something like this. In case the destination directory
    does not exist, the copy module calls another module to create the directory path. This broke
    the variable 'destination' into parts. Because it was passed as a parameter,
    it was incompletely returned. For instance, from an ASCIIZ variable like this one:
    "C:\Matusovski\Semen\Moskow" only the part "Moskow" was to be returned to the copy module.

    I've solved the problem, using a temp. var now in the directory creation process. In DOS
    we simply could use a BYVAL param, in order to leave the original variable untouched,
    but ASCIIZ variables do not allow this. Is this a subject to change for the following release, Lance/Tom?

    Thanks for all the help, again.
    Regards,


    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Leave a comment:


  • Semen Matusovski
    replied
    Egbert --
    About which OS do you talk ?

    Just now I'm under Win2000.

    ChDrive "C:" ' <------------------ Note C:

    MkDir "G:\Sema" ' works perfect

    Could be you specify "Sema" only ?

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Fred Oxenby
    replied
    Perhaps this helps? anyhow there are some useful code...
    Code:
    #Compile Exe
    #Include "\!include\win32api.bas"
    
    Function FSO_GetRoot(ByVal Path$) As String
    Local Tmp$,FS$,SH$
      Tmp$ = UCase$(Path$)
      If (Mid$(Tmp$,1,1)>= "A" And Mid$(Tmp$,1,1)<="Z") And (Mid$(Tmp$,2,1)=":") Then
       Function = Mid$(Path$,1,2) & "\"
      ElseIf Mid$(Path$,1,2)="\\" Then
       FS$ = Rtrim$(Parse$(Path$,"\",3))
       SH$ = Rtrim$(Parse$(Path$,"\",4))
       If Len(FS$)< 2 Then Function = "":Exit Function
       Tmp$ = "\\" & FS$ & "\"
       If Len(SH$) < 1 Then Function = Tmp$:Exit Function
       Function = Tmp$ & SH$ & "\"
      Else
       Function = ""
      End If
    End Function
    
    Function FSO_FolderExists(ByVal FolderSpec$) As Long
    Local fd As WIN32_FIND_DATA
    Local fAttr As Dword
    Local hFind&
      If Len(FolderSpec$)=0 Then Function = %false:Exit Function
      If Right$(FolderSpec$,1)= "\" Then FolderSpec$ = Left$(FolderSpec$,Len(FolderSpec$)-1)
      hFind& = FindFirstFile(ByVal StrPtr(FolderSpec$), fd)
      If hFind& = %INVALID_HANDLE_VALUE Then Function = %false :Exit Function
      Call FindClose(hFind&)
      fAttr = fd.dwFileAttributes
      Function = %True
      'Directory|NotTemporary
      If (Bit(fAttr, 4)=0) Or (Bit(fAttr,8)=1) Then Function = %false
    End Function
    
    Function FSO_CreateFolder(ByVal PathSpec$) As Long
    Local Tmp$,Root$,Rest$,cnt&,i%
    Dim DirPath()As String
    ReDim DirPath(1 To 1)As String
      If Right$(PathSpec$,1)= "\" Then PathSpec$ = Left$(PathSpec$,Len(PathSpec$)-1)
    '--Skapa Root/Rest-------------------------------
      If IsFalse FSO_FolderExists(PathSpec$) Then
        Root$ = FSO_GetRoot(PathSpec$)
        Rest$ = Remove$(PathSpec$,Root$)
        If Len(Rest$) = 0 Then Function = 0:Exit Function
        Cnt& = 0
        For i% = 1 To ParseCount(Rest$,"\")
         Tmp$ = Trim$(Parse$(Rest$,"\",i%))
         If Len(Tmp$) Then
          Incr Cnt&:ReDim Preserve DirPath(1 To Cnt&)
          DirPath(Cnt&)=Tmp$
         End If
        Next i%
        If Cnt& = 0 Then Function = 0:Exit Function
    '--Skapa biblioteken-----------------------------
        On Error Resume Next
        Rest$ = Left$(Root$,Instr(-1,Root$,"\")-1)
        For i% = 1 To Cnt&
         Rest$ = Rest$ & "\" & DirPath(i%)
         Call CreateDirectory(ByVal StrPtr(Rest$),ByVal %NULL)
        Next i%
      End If
      Function = FSO_FolderExists(PathSpec$)
    End Function
    
    
    Function FSO_CopyCDFile(ByVal SrceFile$,ByVal DestFile$,ByVal OverWrite&)As Long
    Local DestDir$
      DestDir$ = Left$(DestFile$,Instr(-1,DestFile$,"\"))
      If IsFalse FSO_CreateFolder(DestDir$)Then
       Function = 100:Exit Function
      End If
      If IsFalse CopyFile(ByVal StrPtr(SrceFile$), _
                          ByVal StrPtr(DestFile$), _
                          OverWrite&) Then
       Function = GetLastError
       Exit Function
      End If
      If IsFalse SetFileAttributes(ByVal StrPtr(DestFile$), _
                                   %FILE_ATTRIBUTE_NORMAL) Then
       Function = GetLastError
       Exit Function
      End If
      Function = 0
    End Function
    Function PbMain()As Long
      Print fso_copycdfile("D:\SETUP.HLP","C:\!!!XXX\SETUP.HLP",1)
      waitkey$
    End Function
    Oops, you had already posted your solution..

    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited November 08, 2000).]

    Leave a comment:


  • Egbert Zijlema
    replied
    Problem solved, I guess!
    The executable runs from D: (during the test phase). The stuff to copy is on the CD-rom
    (drive E:, in my situation). Obviously MKDIR can only create a directory on the drive where
    the app. is running. In other words, you have to CHDIR first. This did the trick:
    Code:
    CHDRIVE szDestination
    IF Exist(szDestination) = 0 THEN MKDIR szDestination
    It ran several times, one after each other, without causing problems anymore. Can anyone
    acknowledge this is "the" adequate solution?

    Regards,

    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Leave a comment:


  • Egbert Zijlema
    replied
    Semen,

    I've tried the API-call as well, like this:
    Code:
    ret& = CopyFile(sourcepath, destpath, %NULL)
    NULL, in this case, means that an existing file should be overwritten (so WIN32.HLP).
    But there is no result (ret& returns zero), simply because the
    destination directory does not exist. Before my app. starts copying, it tries to make
    the new directory, using Basic's MKDIR. It's a 'single' directory, something like
    "C:\MYTEMP", so that should be no problem.
    Anyhow, the circumstances you're talking about (existing read-only file, file open,
    not enough disk space) are not causing the problem.
    Any additional idea?

    Regards and thanks for being 'first aid' again.


    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Leave a comment:


  • Semen Matusovski
    replied
    Egbert --

    Simple FileCopy is not enough.
    There is a lot of reasons, when OS doesn't execute this operation.

    At first, it's better to use API CopyFile to specify that it's allowed to overwrite file.

    But even with CopyFile could be --

    - file already exists on disk and has attribute read-only or is openened by another program
    - exist a folder with the same name
    - not enough disk space and so on.

    About "speed" - perhaps, with some old network clients.
    But I don't beleive that it's has any relation to your problem.



    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Egbert Zijlema
    started a topic FileCopy

    FileCopy

    Problems with copying files in PBDLL60!
    Yes, I've done a search throughout all the forums and did find a lot of
    information, but no hints that point to a workaround.

    Very often, when my app. has to copy files from a CD-rom to the hard disk,
    the files do not appear in the destination directory.

    After what I've read on this subject it may be due to a speed problem, that
    the new directory (MKDIR pathname) is not ready when copying starts,
    but even with a long SLEEP in between I don't create a solution. How do installers
    solve that problem?

    BTW: the module finds the file names on the CD. They are correctly reported
    in a modeless dialog.


    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/
Working...
X