Jump to content

How to dircopy without waiting ?


Recommended Posts

Is there a way to execute dircopy (or any code for that matter )without having script to wait for it to complete before executing next line of code ?

I just want to figure out how to make a folder copy progress bar.

I searched forum but didnt find any simple once that would make sense to me (newby)

Any help is appreciated. :(

Hooray for script examples :)

Thanks.

Link to comment
Share on other sites

have you tried AdlibRegister ? check help file

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

interesting

The way this works is it would (if function is not called previously) skip over it once and only then execute the function.

Executed function would still dircopy for a while before ended.

I was wondering if there was some way for dircopy to work and continue script after execution of dircopy so that next lines would determine file size and such to calculate progress percentage same way as this example:

#include <ProgressConstants.au3>
$AppVersionFile = "/name.version"
$AppFile = "/name.rar"
                $Size = InetGetSize ("http://www." & $AppFile,1)
               $UpdatedFile = InetGet ("http://www." & $AppFile,@TempDir & "\name",1,1)
               ProgressOn("Download progress", "Downloading file ", "0 %")
                   For $i = 1 to $Size step 1
                       $GetCurrentDownloadSTatus = InetGetInfo($UpdatedFile)
                       $percentDownloaded = Round($GetCurrentDownloadSTatus[0]*100/$Size, 2)
                       ProgressSet($percentDownloaded, $percentDownloaded & " %")
                       ;GUICtrlSetData ($progress,$percentDownloaded)
                           If InetGetInfo($UpdatedFile,2) Then
                               InetClose($UpdatedFile)
                               ExitLoop
                           Else
                               ContinueLoop
                           EndIf
                       Next
ProgressOff()
ProgressSet(100 , "100%", "Download completed.")
           $SaveTo = FileSaveDialog ("Save File As",@DesktopDir & "\" & $AppFile,"WinRar Compressed file (name.rar)",2+16,"name.rar")
           If $SaveTo = "" Then
           Elseif $SaveTo > "" Then
           EndIf

See in this case InetGet has a switch to continue without waiting allowing calculation process to begin before it finished copying.

I could use Run (@comspec & "Xcopy blah blah blah") but thought i'd rather doing from autoit script (for system restart reasons)

Edited by madasraka
Link to comment
Share on other sites

You may find it better to use DirMove() instead of DirCopy() for this script. If the directory exists on the same harddrive partition, then it will just make changes to the master file table, but if on another partition/drive, then it does a copy (to destination) and delete (from source) operation. You may find this will be quicker and more convenient.

Link to comment
Share on other sites

This works :( but it invvolves Xcopy whic is not my favorite

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
$Form1 = GUICreate("",200,100)
$button = GUICtrlCreateButton ("Push me",70,0)
$GUIprogressBAR = GUICtrlCreateProgress (0,40,200,40)
$edit = GUICtrlCreateEdit ("",0,80,200,20)
GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
       Case $GUI_EVENT_CLOSE
           Exit
       Case $button
          Backup()
   EndSwitch
WEnd

Func Backup()
DirCreate (@scriptDir & "\BackupDir")
Run (@ComSpec & ' /k xcopy /E/D/Y ' & '"C:\Program Files" "BackupDir"')
$Size = DirGetSize ("C:\Program Files")
For $i = 1 to $Size step 1
    $GetBackupSize = DirGetSize (@scriptDir & "\BackupDir")
    $RoundResult = Round ($GetBackupSize*100/$Size)
    GUICtrlSetData ($GUIprogressBAR,$RoundResult)
If $RoundResult = 100 Then
    MsgBox(0,'Status','Backup Complete')
    ExitLoop
Else
    ContinueLoop
EndIf

Next
EndFunc
MsgBox(0,'','EXIT')
Edited by madasraka
Link to comment
Share on other sites

I cant move files because this is backup script.

I wonder if dirgetsize returns dir size on disk ?

Reasons is that NTFS and FAT32 partitions have different file size on disk due to NTFS compression.

Ah, sorry. I did not realize that is a backup.

An option is perhaps starting another AutoIt process to handle DirCopy(). AutoIt will run from your main script and run a line of code. The below code is idea only code so is not working code but it can be with your modification to suit.

$source = 'sourcepath here'
$destination = 'destinationpath here'
Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "' & @ScriptFullPath & '" "Dircopy(' & $source & ',' & $destination & ')"')

Edit:

Upon later review, @ScriptFullPath should be omitted

$source = 'sourcepath here'
$destination = 'destinationpath here'
Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "Dircopy(' & $source & ',' & $destination & ')"')

Sorry again for any inconvenience.

Edited by MHz
Link to comment
Share on other sites

so this will execute the line as RUN withing same script and continue loading next line of code without stopping the process ?

Yes. Just like your xcopy using @Comspec, this simply uses @Aut2Exe (2nd instance of AutoIt interpreter). But if compiled, uses internal AutoIt interpreter rather then external AutoIt3.exe! It will Run() as exampled and continue without waiting for completion.

So let me explain again:

It runs another instance of the interpreter, whether internal (compiled script) or external (uncompiled script), with the line of code given as a parameter, and your main script will continue.

Look at "Using AutoIt" -> "Command Line Parameters" in help file for more info.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...