Jump to content
Sign in to follow this  
Cyri

File copy no attributes

Recommended Posts

Cyri

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?

Share this post


Link to post
Share on other sites
Authenticity

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.

Share this post


Link to post
Share on other sites
Cyri

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.

Share this post


Link to post
Share on other sites
Authenticity

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.

Share this post


Link to post
Share on other sites
Cyri

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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.