Sign in to follow this  
Followers 0
rudi

Looking for a "DirCopyWithProgress()"

11 posts in this topic

Hi.

I want to do a DirCopy() with a progress bar.

I found some snippets here, but fail to use them :P . So before going to deep I simply want to ask if I just miss :P such a function existing in the latest Autot3 version?

I was wondering to use a frequent call of DirGetSize($DestDir), but

1.) for large folders this takes quite a while.

2.) DirCopy() is busy until the copy is done... (no "go backgroud"), so I can't see how to use DirCopy() for this purpose.... :D

With these two

$BackGround=1
InetGet($URL,$localfile,$reload,$background) 
$done=@InetGetBytesReadoÝ÷ Ú+wödz+hv.r­)à~â׫ë]£   塧l²(ëax%Gjëh×6$BackGround=1
DirCopy($Source,$Destin,$Backgroud)
$done=@DirCopyGetBytesDone

would be soooo ;) nice, but I guess, there is no such thing ;) ?

Thanks, Rudi.

--

I'm using v3.2.10.0 25th November, 2007


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites



Hi,

something like this?

;Copy with Progressbar
#Include <File.au3>

_copyProgress("C:\Downloads\Fotos\Frisur\", 'C:\Downloads\Fotos\Frisur\Test\', '*.jpeg')

Func _copyProgress($From_dir, $Dest_dir, $filter = '*.*')
    Local $count = 0, $dir = ""
    $FileList = _FileListToArray($From_dir, $filter, 0)
    If(Not IsArray($FileList)) And(@error = 1) Then SetError(-1)
    ProgressOn("Copy", "Files :", "0 files")
    For $i = 1 To UBound($FileList) - 1
        If FileGetAttrib($FileList[$i]) = "D" Then $dir = "\*.*"
        If FileCopy($From_dir & "\" & $FileList[$i] & $dir, $Dest_dir & "\", 9) Then
            $count += 1
            ProgressSet($count * 100 / $FileList[0], _
                    "From: " & $From_dir & "\" & @LF & "To: " & $Dest_dir & "\" & @LF & $FileList[$i], _
                    StringFormat('%05.2f', Round(($count * 100 / $FileList[0]), 2)) & " % " & @TAB & $count & "/" & $FileList[0] & " Done")
        EndIf
        Sleep(300)
    Next
    ProgressSet(100, "Done", "Complete")
    Sleep(500)
    ProgressOff()
    Return 1
EndFunc   ;==>_copyProgressoÝ÷ Úí+ºÚ"µÍ[ÈÑ[PÛÜJ ÌÍÙÛQ[K ÌÍÝÙ[JBØØ[    ÌÍÑÑÔTÔÓÖQTÈHMØØ[    ÌÍÑÑÔÒSTTÑÔTÔÈHM  ÌÍÝÚ[Ú[HØÜX]J    ][ÝÜÚ[XØ][Û][ÝÊB ÌÍÝÚ[Ú[[YÜXÙJ    ÌÍÝÙ[JKÛÜRJ   ÌÍÙÛQ[K ÌÍÑÑÔTÔÓÖQTÊB[[

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

something like this .... or that?

I prefer the 2nd. one :D

After some tries I realized, that the destination directory has to exist already.

$Source = "FooBar"
$Dest = "BarFoo" ;-)

For $i = 0 To 9
    $dummy = FileOpen(@ScriptDir & "\" & $Source & "\" & $i & ".txt", 2)
    FileWriteLine($dummy, $i)
    FileClose($dummy)
    For $k = 0 To 999
        $dummy = FileOpen(@ScriptDir & "\" & $Source & "\" & $i & "\" & $i & "-" & $k & ".txt", 10)
        FileWriteLine($dummy, $i & $k)
        FileClose($dummy)
    Next
Next
_FileCopy(@ScriptDir & "\" & $Source & "\*.*", @ScriptDir & "\" & $Dest & "\")


Func _FileCopy($fromFile, $tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile, $FOF_RESPOND_YES)
EndFunc   ;==>_FileCopy

Is it possible to supress the question "File / folder .... already exists. Yes, Yes to all, no, cancel" ?

How did you know about this $winshell.<something>, I'm asking as I cannot find something covering that in the autoit3 help files?

Thanks for your help, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Xenobiologist Hello! With respect to you: sorry, but your 1-st solution do not work and have a little mistake with If FileGetAttrib($FileList[$i]) = "D" Then $dir = "\*.*", because folder can have few attributes (READONLY, SYSTEM & etc...).

:D

rudi

More solutions for you :P

My code:

Global $aFiles[1]

_DirCopy("d:\download", "c:\wallpaper", 1)

Func _DirCopy($iSource, $iDest, $flag = 1) ;$flag = 1 - Overwrite files and folders
    Local $iFirstFile, $iNextFile, $iFullFile, $iRec = ''
    Local $iFirstFile = FileFindFirstFile($iSource & "\*.*")
    If @error Then Return
    
    While 1
        $iNextFile = FileFindNextFile($iFirstFile)
        If @error Then
            Local $iPercent, $iDestDir, $oFile, $oFolder, $i
            
            If $flag > 0 Then
                $oFile = 9
                $oFolder = 1
            Else
                $oFile = 0
                $oFolder = 0
            EndIf
            
            If Not FileExists($iDest) Then DirCreate($iDest)
            
            ProgressOn("Copy", "File: ", "", -1, -1, 16)
            
            For $i = 1 To $aFiles[0]
                $iPercent = Round($i / $aFiles[0] * 100, 2)
                ProgressSet($iPercent, $aFiles[$i] & " copyed", $iPercent & "% done")
                If StringInStr(FileGetAttrib($aFiles[$i]), "D") Then
                    $iDestDir = $iDest &"\"& StringRegExpReplace($aFiles[$i], "^.*\\", "")
                    If Not FileExists($iDestDir) Then DirCreate($iDestDir)
                    DirCopy($aFiles[$i], $iDestDir, $oFolder)
                Else
                    FileCopy($aFiles[$i], $iDest, $oFile)
                EndIf
            Next
            
            ProgressSet(100, "Done", "Complete")
            Sleep(1000)
            ProgressOff()
            ExitLoop
        EndIf
        
        $iFullFile = $iSource &"\"& $iNextFile
        $aFiles[0] += 1
        ReDim $aFiles[$aFiles[0] + 1]
        $aFiles[$aFiles[0]] = $iFullFile
    WEnd
    FileClose($iFirstFile)
EndFuncoÝ÷ ØÚ-'(u殶­seôfÆT6÷WgV÷C¶C¢b3#µfFVògV÷C²ÂgV÷C¶3¢b3#µFV×gV÷C² ¤gVæ2ôfÆT6÷Wb33cµ6÷W&6RÂb33c´FW7B¢bæ÷BfÆTW7G2b33cµ6÷W&6RFVâ&WGW&â6WDW'&÷"¢&öw&W74öâgV÷CµôfÆT6÷WFVÖògV÷C²ÂgV÷C´6÷âââgV÷C²¢b33c·6÷&öw&W75&÷WFæRÒFÆÄ6ÆÆ&6µ&Vv7FW"gV÷Cµô6÷&öw&W75&÷WFæRgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷C·VçCcC·VçCcC·VçCcC·VçCcC¶Gv÷&C¶Gv÷&C·G#·G#·G"gV÷C²¢FÆÄ6ÆÂgV÷C¶¶W&æVÃ3"æFÆÂgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷C´6÷fÆTWgV÷C²Âð¢gV÷C·7G"gV÷C²Âb33cµ6÷W&6RÂð¢gV÷C·7G"gV÷C²Âb33c´FW7BÂð¢gV÷C·G"gV÷C²ÂFÆÄ6ÆÆ&6´vWEG"b33c·6÷&öw&W75&÷WFæRÂð¢gV÷C·G"gV÷C²ÂÂð¢gV÷C¶çBgV÷C²ÂÂð¢gV÷C¶çBgV÷C²Â¢FÆÄ6ÆÆ&6´g&VRb33c·6÷&öw&W75&÷WFæR¢6ÆVW¢&öw&W74öfb¤VæDgVæ0 ¤gVæ2ô6÷&öw&W75&÷WFæRb33cµF÷FÄfÆU6¦RÂb33cµF÷FÄ'FW5G&ç6fW'&VBÂb33cµ7G&VÕ6¦RÂb33cµ7G&VÔ'FW5G&ç6fW'&VBÂb33c¶Gu7G&VÔçVÖ&W"Âb33c¶Gt6ÆÆ&6µ&V6öâÂb33c¶6÷W&6TfÆRÂb33c¶FW7FæFöäfÆRÂb33c¶ÇFF¢b33cµ&V6VçBÒb33cµF÷FÄ'FW5G&ç6fW'&VBòb33cµF÷FÄfÆU6¦R¢¢&öw&W756WBb33cµ&V6VçBÂgV÷CµW&6VçC¢gV÷C²fײ&÷VæBb33cµ&V6VçBÂfײgV÷C²RgV÷C²¢&WGW&â¤VæDgVæ2³ÓÒfwCµô6÷&öw&W75&÷WFæPoÝ÷ Ù«­¢+Ù±½°
½¹ÍÐÀÌØí=}
=AdôÁàÀÀÀÈì
½Á¥ÌÑ¡¥±ÌÍÁ¥¥¥¸Áɽ´Ñ¼Ñ¡±½Ñ¥½¸ÍÁ¥¥¥¸ÁQ¼)±½°
½¹ÍÐÀÌØí=}1QôÁàÀÀÀÌì±ÑÌÑ¡¥±ÌÍÁ¥¥¥¸Áɽ´¡ÁQ¼¥Ì¥¹½É¤)±½°
½¹ÍÐÀÌØí=}5=YôÁàÀÀÀÄì5½ÙÌÑ¡¥±ÌÍÁ¥¥¥¸Áɽ´Ñ¼Ñ¡±½Ñ¥½¸ÍÁ¥¥¥¸ÁQ¼)±½°
½¹ÍÐÀÌØí=}I95ôÁàÀÀÀÐìI¹µÌÑ¡¥±ÌÍÁ¥¥¥¸Áɽ´()±½°
½¹ÍÐÀÌØí=}11=]U9

;)

Edited by rasim

Share this post


Link to post
Share on other sites

Xenobiologist Hello! With respect to you: sorry, but your 1-st solution do not work and have a little mistake with If FileGetAttrib($FileList[$i]) = "D" Then $dir = "\*.*", because folder can have few attributes (READONLY, SYSTEM & etc...).

:D

However this is not FolderGetAttrib(), it is FileGetAttrib() and does indeed return "D" for a folder.

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

GEOSoft

Hello! I don`t teach you, you guru for me. :D I just show the simple example:

If FileGetAttrib("c:\RECYCLER") = "D" Then MsgBox(0, "Check", "This is folder")

Share this post


Link to post
Share on other sites

GEOSoft

Hello! I don`t teach you, you guru for me. :D I just show the simple example:

If FileGetAttrib("c:\RECYCLER") = "D" Then MsgBox(0, "Check", "This is folder")
OK I see what you are saying now. It should have been

If StringInStr(FileGetAttrib("c:\RECYCLER"), "D") Then MsgBox(0, "Check", "This is folder")

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

can you have the program check the source files and copy the files if newer than the destination?

Share this post


Link to post
Share on other sites

can you have the program check the source files and copy the files if newer than the destination?

If FileGetTime ( Source , 0 , 1) > FileGetTime ( Destination , 0 , 1) Then

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

More please I am trying convert a batch file

The dos commands are

xcopy /D /C X:\*.exe C:\Temp\

In the past i was able to get away with just having auto it run the batch file in a hidden window but now it seems to get stuck in the task managers process tabs.

Can you help?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

More please I am trying convert a batch file

The dos commands are

xcopy /D /C X:\*.exe C:\Temp\

In the past i was able to get away with just having auto it run the batch file in a hidden window but now it seems to get stuck in the task managers process tabs.

Can you help?

Try this:

Run(@ComSpec & ' /c xcopy /d /c "X:\*.exe" "c:\temp"', "", @SW_HIDE)

:)

Edited by rasim

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