Sign in to follow this  
Followers 0
Stretch

Copying from removable media

3 posts in this topic

I've got a script that copies images from various removable media drives. It checks all drives in my computer, and if it is removable and ready, then it checks to see how many images are on the media, copies them to a temp directory and checks how many were copied. It is designed to check if multi media card readers work on all slots.

Problem is, if a media card is removed mid copy, then the script bombs.

What kind of error handling can i do on it, so that if the media is removed, the script continues.

Stretch.

Share this post


Link to post
Share on other sites



Post your script.

... and how about the exact error you get when you create this scenario?


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

#include <Array.au3>
#include <GuiConstants.au3>



$var = DriveGetDrive( "all" )

Dim $avArray[1]

If NOT @error Then
    For $i = 1 to $var[0]
        $type=DriveGettype($var[$i])
        $ready = DriveStatus($var[$i])
    ;$name=DriveGetLabel($var[$i])
        if $type = "Removable" and $ready = "Ready" then
        ;DirCreate("d:\cardtest\" & StringTrimRight($var[$i],1))
            
            ProgressCopy($var[$i] & "\","d:\cardtest\"  & StringTrimRight($var[$i],1))
            $before = DirGetSize($var[$i] & "\",1)
            $after = DirGetSize("d:\cardtest\"  & StringTrimRight($var[$i],1) & "\",1)
            Msgbox(0,"Files on media " & $var[$i] & "\" ,$before[1],1)
            Msgbox(0,"Files Copied from " & $var[$i] & "\",$after[1],1)
            
            
            If $before[1] = $after[1] then
                _ArrayAdd( $avArray,$var[$i])
            Else
                msgbox(0,"","Issue with Drive " & $var[$i])
            EndIf
            
            
            
        EndIf
    Next
EndIf

_ArraySort($avArray)

        $string=""
        For $i = 1 to Ubound ($avArray) -1
            $String = $String &  $avArray[$i] & @crlf
        Next        





msgbox(0,"","The were "&($i-1)&" media successfully copied!"&@CRLF&@CRLF&$String)

msgbox(0,"","Press to run exit and remove copied data.")

DirRemove("d:\cardtest\",1)



Func ProgressCopy($current, $destination,  $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$createDir = 1 ,$Run1 = 0 )
    
;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
        If $createDir > 0 then $createDir = 8
        Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text,  $LocalPercent, $mustRestart=0
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
        $source = $current
        If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
        If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
        $tosearch = $current
        $Overall = DirGetSize($tosearch, 1)
        $OverallQty = $Overall[1]
        Global $PrCopyGui = GUICreate("Copying Files", 420, 100, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
        $Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
        GUICtrlSetColor(-1, 32250)
        $Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
        $Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)
        GUISetFont(10, 600)
        GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
        GUISetState(@SW_SHOW)
        GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
        $Run1 = 1
    EndIf
    
    $Size = DirGetSize($current, 3)
    $Qty = $Size[1]
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            $Qty -= 1
            $LocalPercent = 100 - (($Qty / $Size[1]) * 100)
            $OverallQty -= 1
            $overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
            GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")
            GUICtrlSetData($progressbar1, $overallpercent)
            GUICtrlSetData($progressbar2, $LocalPercent)
            GUICtrlSetData($Progress2Text, "Copying File " & $file)
            
            If $useMultiColour then 
                GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
                GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
            EndIf
            
            $success = FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite + $createDir)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
            If $success = 0 Then
                FileCopy($current & "\" & $file, @tempdir & StringTrimLeft($current, StringLen($source)) & "\" & $file,9)
                _CopyAfterRestart(@tempdir & StringTrimLeft($current, StringLen($source)) & "\" & $file,$destination & StringTrimLeft($current, StringLen($source)) & $file)
                $mustRestart=1
            EndIf
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
            GUICtrlSetData($Progress1Text, $current & "\" & $file)
            ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $createDir, $overwrite,1)
        EndIf
    WEnd
    FileClose($search)
;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
    If $overallpercent = 100 Then
        GUICtrlSetData($Progress0Text, "Total Progress 100% completed")
        GUICtrlSetData($progressbar1, 100)
        GUICtrlSetData($progressbar2, 100)
        GUICtrlSetData($Progress2Text, "Done!")
        Sleep(2000)
        GUIDelete($PRCopyGui)
        $Run1 = 0
        If $mustRestart = 1 then Msgbox (0,"Warning","You must restart your computer for all the copied files to take effect",10)
    EndIf
EndFunc  ;==>ProgressCopy

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  
Followers 0