Sign in to follow this  
Followers 0
bucktech

FileCopy Problem

3 posts in this topic

trying to do the dircopy thing, there are 12 folders a few files and about 5.5MB total to move to a mapped drive.

However I only get 3 folders copied, I have even changed to different machines and have the same problem.

I have done it the hard way.

create a dir in the destination then copy the contents using filecopy and it worked, just more typing is all.

Any suggestions?

CODE
$LocalSettingsMS = "U:\appdata\LocalSettings\Microsoft"

DirCopy(@UserProfileDir & "\Local Settings\Application Data\Microsoft", $LocalSettingsMS)

Share this post


Link to post
Share on other sites



trying to do the dircopy thing, there are 12 folders a few files and about 5.5MB total to move to a mapped drive.

However I only get 3 folders copied, I have even changed to different machines and have the same problem.

I have done it the hard way.

create a dir in the destination then copy the contents using filecopy and it worked, just more typing is all.

Any suggestions?

CODE
$LocalSettingsMS = "U:\appdata\LocalSettings\Microsoft"

DirCopy(@UserProfileDir & "\Local Settings\Application Data\Microsoft", $LocalSettingsMS)

I think what you may be running into with that folder is a problem with File Attributes.

I would start by using a recursive folder search and get the folder names into an array. Then put the Array into a loop that copies the folders with an

If @Error then ContinueLoop

That will let you see which ones are causing the problem

Then see what you can do with FileSetAttrib.

Remember that since some of those folders are system critical you should use FileGetAttrib before changing the attrib so that you can immediatly reset them.

You will also find that some folders will just refuse to be copied.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Following GEOSoft advice

I would start by using a recursive folder search and get the folder names into an array. Then put the Array into a loop that copies the folders

you can use or modify this script done by craig.gill

#include <GUIConstants.au3>

Global $OverallQty, $Overall, $Progress0Text, $progressbar1, $Progressbar2, $Progress2Text, $source, $Progress1Text
Global $OverallPercent
Local $LocalSettingsMS = "U:\appdata\LocalSettings\Microsoft"

ProgressCopy(@UserProfileDir & "\Local Settings\Application Data\Microsoft", $LocalSettingsMS)

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "", $overwrite = 1 ,$Run1 = 0 )
   ;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
        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 = StringTrimRight($destination, 1)
        $tosearch = $current
        $Overall = DirGetSize($tosearch, 1)
        $OverallQty = $Overall[1]
        $PrCopyGui = GUICreate("Copying Files", 420, 100, -1, -1, BitOR($WS_BORDER, $WS_POPUP), $WS_EX_TOPMOST)
        $Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20,$PBS_SMOOTH)
        $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)
        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

            $iRet = FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $overwrite + 8)
            If Not $iRet And (Not FileExists($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file) Or $overwrite) Then
                RunWait(@ComSpec & ' /c xcopy "'& $current & '\' & $file & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" /g /h /r /y /z', @TempDir, @SW_HIDE)
            EndIf
   
      FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
        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, $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
    EndIf
EndFunc ;==>ProgressCopy

Func _ChangeColour($start)
    $Redness = Int(255 - ($start  / 100 * 512))
    If $Redness < 0 Then $Redness = 0
    $Greeness = Int(($start  / 100 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0
    $Blueness = Int(255 - ($Redness + $Greeness))
    Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
EndFunc

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

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