Jump to content

Recommended Posts

Posted

Does anyone have a copy method that doesn't copy file attributes? I'm working with DVD media and every file that gets copied off using the FileCopy() method copies the files as read-only. I've added the FileSetAttribute() to my script, but I'm wondering if there's a better way?

Posted

You can code your own FileCopy to use generic attributes with new created files. For example:

_FileCopy('C:\boot.ini', @DesktopDir & '\boot.ini')

Func _FileCopy($sFileSource, $sFileDest)
    Local $hFileSource, $hFileDest
    Local $BinSource
    
    If Not FileExists($sFileSource) Or StringRight($sFileSource, 1) = '\' Then Return SetError(1)
    
    $hFileSource = FileOpen($sFileSource, 16)
        If $hFileSource = -1 Then Return SetError(2)
        
    $hFileDest = FileOpen($sFileDest, 16+2)
        If $hFileSource = -1 Then
            FileClose($hFileSource)
            Return SetError(3)
        EndIf
        
    $BinSource = FileRead($hFileSource)
    
    FileWrite($hFileDest, $BinSource)
    
    FileClose($hFileDest)
    FileClose($hFileSource)
EndFunc

You can use the window API functions and write using buffer so you can show a progress using the WriteFileEx's lpCompletionRoutine.

Posted

You can code your own FileCopy to use generic attributes with new created files. For example:

_FileCopy('C:\boot.ini', @DesktopDir & '\boot.ini')

Func _FileCopy($sFileSource, $sFileDest)
    Local $hFileSource, $hFileDest
    Local $BinSource
    
    If Not FileExists($sFileSource) Or StringRight($sFileSource, 1) = '\' Then Return SetError(1)
    
    $hFileSource = FileOpen($sFileSource, 16)
        If $hFileSource = -1 Then Return SetError(2)
        
    $hFileDest = FileOpen($sFileDest, 16+2)
        If $hFileSource = -1 Then
            FileClose($hFileSource)
            Return SetError(3)
        EndIf
        
    $BinSource = FileRead($hFileSource)
    
    FileWrite($hFileDest, $BinSource)
    
    FileClose($hFileDest)
    FileClose($hFileSource)
EndFunc

You can use the window API functions and write using buffer so you can show a progress using the WriteFileEx's lpCompletionRoutine.

This seems inefficient at best. What if the files I'm copying are huge? Also, the function above would only work for text files. I'm copying all different file types.
Posted

Not necessary. It may be slow, true, it's working only for .txt file, nope. Read the last comment. You can use WriteFileEx or ReadFileEx and use a completion routine so you can buffer it and show progress, well possible using just WriteFile and ReadFile.

Posted

Not necessary. It may be slow, true, it's working only for .txt file, nope. Read the last comment. You can use WriteFileEx or ReadFileEx and use a completion routine so you can buffer it and show progress, well possible using just WriteFile and ReadFile.

Ah, I missed that part. I was hoping for a slam dunk but it doesn't sound like it's going to be. I think I'll stick with the FileSetAttrib() for now. Or I suppose I could shell out to copy, xcopy. or robocopy intead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...