Jump to content

Copying files/directories in win7 with progress bar


Recommended Posts

Hi.

I`m new at this forum. Therefore I will pologize if there are many answers about this theme. But i have a problem.

I have made a script for copying a P2-card (videocard) from a cardreader to a server. And it works OK. But the students ask for a progress bar with time left of copying. And I tried to implement some new lines in the script from ;Define source and target (line 56).

Then I got the problem. For me, it seems that Win7 set the size of destination when xcopy start copying the last file. Therefor the script told me that the Copy was finnish when it starts copying the last clip.

Is there a way around it? A metode there will give me the right time and percents?

This is the script:

;=====================================================

; Copying P" card to server

;=====================================================

;=====================================================

; Versjon 2.1

; HVO amf

; Autor: Reidulf Botn

;200910

;=====================================================

#include <GuiConstantsEx.au3>

#include <Date.au3>

#include <WindowsConstants.au3>

;Checking if the server is mapped.

If DriveMapGet("P:") <> ("\\media\P2\P2_H10\1TV_H10") Then

DriveMapAdd("P:","\\media\P2\P2_H10\1TV_H10")

;MsgBox(0,"P2","Mapper server")

Else

EndIf

MsgBox(0,"Start","Sett inn kortet")

;Checking if there is a card in the reader

If FileExists("E:\LASTCLIP.TXT") Then

;Asking for input

$mappenavn = InputBox("Navn","Skriv inn navn på saken", ""," M")

If @error = 1 Then

MsgBox(0,"Cancel","Ikke bruk Cancel" & @LF & "Prøv på nytt")

Exit

EndIf

$initial = InputBox("Initialer","Skriv inn initialene dine", ""," M")

If @error = 1 Then

MsgBox(0,"Cancel","Ikke bruk Cancel" & @LF & "Prøv på nytt")

Exit

EndIf

;writing error at screen

Else

MsgBox(0,"Feilmelding","Sett inn kortet skikkelig")

EndIf

;making folders at server

DirCreate("P:\" & $mappenavn & $initial & _DateTimeFormat( _NowCalc(),2))

$dir = ("P:\" & $mappenavn & $initial & _DateTimeFormat( _NowCalc(),2))

Sleep(1000)

;Define source and target

$source = "E:\"

$dest = $sdir

;size of source and target

$ssize = DirGetSize($source)

$dsize = DirGetSize($dest)

if $dsize < 0 then

$dsize = 0

EndIf

;Staring prosess bar and set it to 0

ProgressOn("Kopierer filer ...", "", "0 %")

ProgressSet(0, "Kalkulerer kopieringstid...")

Sleep(1000)

; Starting timer and XCOPY

$tbegin = TimerInit()

Run(@ComSpec & " /c xcopy /y /e " & $source & "*.* " & $dest, "", @SW_HIDE)

For $percent = 0 to 100

$copied = DirGetSize($dest) - $dsize ;estimating how much is copied

$percent = Round(($copied/$ssize),2) * 100 ; percent copied

$tdiff = TimerDiff($tbegin) ; time difference from start copying

$tmin = Round(((100/$percent) -1) * ($tdiff/60000)) ; resttime in minutes

$tsec = Round(((100/$percent) -1) * ($tdiff/1000)) ;resttime in seconds

;If remaining time is less than one minute, prosses bar will show the time in seconds

If $tsec < 60 Then

$tdisplay = " Cirka " & $tsec & " sekund igjen"

Else

$tdisplay = " Cirka " & $tmin & " minutter igjen"

EndIf

ProgressSet( $percent, "Prosent kopiert: " & $percent & " %" & @LF & $tdisplay)

Sleep(1000)

Next

ProgressSet(100, "Ferdig", "")

Sleep(1500)

ProgressOff()

Exit

Link to comment
Share on other sites

i think that your looking for this if im not wrong (dono if itl work for win7, on xp i don`t have problems)

http://msdn.microsoft.com/en-us/library/aa363854(v=VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa363852(v=VS.85).aspx

<--- click it

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
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...