Sign in to follow this  
Followers 0
RichE

Xcopy GUI

20 posts in this topic

#1 ·  Posted (edited)

Hi Guys/Gals,

if in your job, like me you have to lots shunt files around on regular basis and use xcopy to do this, then this may come in useful for you.

I originally wrote version 1 years ago, but decided that it deserved some more of my time, so here it is version 2

Posted Image

and here's the code

#cs ----------------------------------------------------------------------------
 
AutoIt Version: 3.3.6.1
Author:         Richard Easton#include <ButtonConstants.au3>
Script Function:
XCopy GUI Version 2
Feature:
Hidden Cmd window with in gui CMD Progress.
More checkbox functions
 
#ce ----------------------------------------------------------------------------
 
; Script Start - Add your code below here
 
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
 
$Xcopy_GUI = GUICreate("XCopy GUI Version2", 834, 600, -1, -1)
 
;target information
$Target_Information = GUICtrlCreateGroup(" Target Information ", 8, 16, 817, 73)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Source", 16, 40, 38, 17)
$SourceInput = GUICtrlCreateInput("", 80, 37, 577, 21)
GUICtrlSetColor(-1, 0xF0F0F0)
GUICtrlSetBkColor(-1, 0x008080)
$Sourcebtn = GUICtrlCreateButton("Browse to Source", 664, 36, 153, 23)
GUICtrlCreateLabel("Destination", 16, 64, 57, 17)
$DestInput = GUICtrlCreateInput("", 80, 60, 577, 21)
GUICtrlSetBkColor(-1, 0x1B80E4)
$Destbtn = GUICtrlCreateButton("Browse to Destination", 664, 60, 153, 21)
GUICtrlSetState($Destbtn, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
 
;xcopy options
$Xcopy_Options = GUICtrlCreateGroup(" XCopy Options ", 8, 96, 817, 137)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Option_subdirs = GUICtrlCreateCheckbox("Copy directories and  subdirectories, including empty ones.", 16, 112, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_assumedir = GUICtrlCreateCheckbox("If Destination does not exist, assume that it is a directory.", 16, 131, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_overwrite = GUICtrlCreateCheckbox("Suppress prompting to confirm overwrite. (will overwrite if checked)", 16, 151, 400, 17)
$option_errorcontinue = GUICtrlCreateCheckbox("Continue even if an error occurs.", 16, 172, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_verify = GUICtrlCreateCheckbox("Verifies the size of each new file.", 16, 191, 400, 17)
$option_noname = GUICtrlCreateCheckbox("Does not display file names while copying.", 16, 210, 400, 17)
$option_encryptedfiles = GUICtrlCreateCheckbox("Copies encrypted files to destination, that does not support it.", 424, 210, 400, 17)
$option_copyhands = GUICtrlCreateCheckbox("Copies hidden and system files.", 424, 191, 400, 17)
$option_copyarchoff = GUICtrlCreateCheckbox("Only copies files with the archive bit set, turning it off after.", 424, 112, 400, 17)
$option_copyarchon = GUICtrlCreateCheckbox("Only copies files with the archive bit set, leaving it on after.", 424, 131, 400, 17)
$option_restartablemode = GUICtrlCreateCheckbox("Copies networked files in restartable mode.", 424, 151, 400, 17)
If @OSVersion = "WIN_XP" Then
$option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
GUICtrlSetState(-1, $GUI_UNCHECKED)
GUICtrlSetState(-1, $GUI_DISABLE)
Else
$option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
EndIf
 
GUICtrlCreateGroup("", -99, -99, 1, 1)
 
;progress pain
$Session_Progress = GUICtrlCreateGroup(" Session Progress ", 8, 240, 817, 321)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Progress = GUICtrlCreateListView("", 16, 256, 801, 292, -1, $LVS_EX_GRIDLINES)
GUICtrlCreateGroup("", -99, -99, 1, 1)
 
;controls
$copy = GUICtrlCreateButton("Proceed with copy", 677, 568, 147, 25)
GUICtrlSetState($copy, $GUI_DISABLE)
 
_GUICtrlListView_AddColumn($Progress, "Description", 580, 0)
_GUICtrlListView_AddColumn($Progress, "Date/Time", 200, 0)
 
GUISetState(@SW_SHOW)
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Sourcebtn
$source = FileSelectFolder("Select Source Folder", "", 1 + 2 + 4)
If @error Then
;check to see if no folder has been selected
MsgBox(48, "Source Folder", "no folder selected or dialogue cancelled", 5)
Else
;update source input
If $source = "computer" Then
MsgBox(48, "Warning!", "Invalid Location selected", 5)
Else
GUICtrlSetData($SourceInput, $source, "")
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Source Location Selected, checking size|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
Sleep(500)
$sourcesize = DirGetSize(GUICtrlRead($SourceInput), 1)
If Round($sourcesize[0] / 1024 / 1024) < 1000 Then
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Source directory size(Mb): " & Round($sourcesize[0] / 1024 / 1024) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
Else
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Source directory size(Gb): " & Round($sourcesize[0] / 1024 / 1024 / 1024, 2) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
EndIf
 
GUICtrlSetState($Destbtn, $GUI_ENABLE)
EndIf
EndIf
Case $Destbtn
$destination = FileSelectFolder("Select Destination Folder", "", 1 + 2 + 4)
;read source location
$source = GUICtrlRead($SourceInput)
If @error Then
;check to see if no folder has been selected
MsgBox(48, "Destination Folder", "no folder selected or dialogue cancelled", 5)
ElseIf $source > "" Then
;check source and destination are the same, if they are display warning!
If $destination = $source Then
MsgBox(48, "Warning!", "Source and Destination cannot be the same!", 5)
Else
If $destination = "computer" Then
MsgBox(48, "Warning!", "Invalid Location selected", 5)
Else;update destination input
GUICtrlSetData($DestInput, $destination, "")
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Destination Location Selected, checking freespace|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
If StringLen(GUICtrlRead($DestInput)) > 3 Then
$destloc = StringLeft(GUICtrlRead($DestInput), 3)
$destfreespace = DirGetSize($destloc, 1)
Else
$destfreespace = DirGetSize(GUICtrlRead($DestInput), 1)
EndIf
;check for Mb or Gb
If Round($destfreespace[0] / 1024 / 1024) < 1000 Then
;Check source is not bigger than destination
If Round($destfreespace[0] / 1024 / 1024) < Round($sourcesize[0] / 1024 / 1024) Then
MsgBox(48, "XCopy GUI", "There is not enough freespace on the destination to copy all data" & @CR & "Please choose another destination")
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Not enough freeSpace on Destination|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
GUICtrlSetData($DestInput, "", "")
Else
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Destination FreeSpace(Mb): " & Round($destfreespace[0] / 1024 / 1024) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
GUICtrlCreateListViewItem("Sufficient freespace to do copy|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
GUICtrlSetState($copy, $GUI_ENABLE)
EndIf
Else
If Round($destfreespace[0] / 1024 / 1024 / 1024, 2) < Round($sourcesize[0] / 1024 / 1024 / 1024, 2) Then
MsgBox(48, "XCopy GUI", "There is not enough freespace on the destination to copy all data" & @CR & "Please choose another destination")
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Not enough freeSpace on Destination|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
GUICtrlSetData($DestInput, "", "")
Else
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Destination FreeSpace(Gb): " & Round($destfreespace[0] / 1024 / 1024 / 1024, 2) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
GUICtrlCreateListViewItem("Sufficient freespace to do copy|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
GUICtrlSetState($copy, $GUI_ENABLE)
EndIf
EndIf
EndIf
EndIf
EndIf
Case $copy
; cmd line for xcopy is
 
ProgressOn("XCopy GUI", "Please Wait", "Checking options", -1, -1)
ProgressSet(10, "Checking Options", "Please Wait")
Sleep(2000)
$subdirs = GUICtrlRead($Option_subdirs)
$assumedirs = GUICtrlRead($option_assumedir)
$overwrite = GUICtrlRead($option_overwrite)
$errorcontinue = GUICtrlRead($option_errorcontinue)
$verify = GUICtrlRead($option_verify)
$noname = GUICtrlRead($option_noname)
$encfiles = GUICtrlRead($option_encryptedfiles)
$copyhands = GUICtrlRead($option_copyhands)
$archoff = GUICtrlRead($option_copyarchoff)
$archon = GUICtrlRead($option_copyarchon)
$restartable = GUICtrlRead($option_restartablemode)
$unbuffered = GUICtrlRead($option_unbuffered)
; 'XCOPY source destination /E /I /Y /C /V /Q /G /H /A /M /Z /J'
 
If $subdirs = 1 Then
$subdirs = "/E "
Else
$subdirs = ""
EndIf
If $assumedirs = 1 Then
$assumedirs = "/I "
Else
$assumedirs = ""
EndIf
If $overwrite = 1 Then
$overwrite = "/Y "
Else
$overwrite = ""
EndIf
If $errorcontinue = 1 Then
$errorcontinue = "/C "
Else
$errorcontinue = ""
EndIf
If $verify = 1 Then
$verify = "/V "
Else
$verify = ""
EndIf
If $noname = 1 Then
$noname = "/Q "
Else
$noname = ""
EndIf
If $encfiles = 1 Then
$encfiles = "/G "
Else
$encfiles = ""
EndIf
If $copyhands = 1 Then
$copyhands = "/H "
Else
$copyhands = ""
EndIf
If $archoff = 1 Then
$archoff = "/A "
If $archon = 1 Then
GUICtrlSetState($option_copyarchon, $GUI_UNCHECKED)
EndIf
Else
$archoff = ""
EndIf
If $archon = 1 And $archoff = 4 Then
$archon = "/M "
Else
$archon = ""
EndIf
If $restartable = 1 Then
$restartable = "/Z "
Else
$restartable = ""
EndIf
If $unbuffered = 1 Then
$unbuffered = "/J"
Else
$unbuffered = ""
EndIf
 
 
ProgressSet(30, "Options Set", "Please Wait")
Sleep(2000)
ProgressSet(40, "Checking Locations", "Please Wait")
$source = GUICtrlRead($SourceInput)
$destination = GUICtrlRead($DestInput)
 
If $source = "" Or $destination = "" Then
MsgBox(48, "Warning!", "There is a problem with one location", 5)
Sleep(2000)
ProgressOff()
Else
Sleep(2000)
ProgressSet(50, "Source and Destination verified", "Please Wait")
Sleep(2000)
EndIf
ProgressSet(80, "Preparing Command", "Please Wait")
$cmdprep = 'Xcopy "' & $source & '" "' & $destination & '" ' & $subdirs & $assumedirs & $overwrite & $errorcontinue & $verify & $noname & $encfiles & $copyhands & $archoff & $archon & $restartable & $unbuffered
 
 
ProgressSet(100, "Ready to go :D", "Checks Complete")
Sleep(2000)
ProgressOff()
 
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Started|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
;subdirs,assumedir,overwrite,errorcontinue,verify,noname,encryptedfiles,copyhands,copyarchoff,copyarchon,restartablemode,unbuffered
;disable the options
GUICtrlSetState($Option_subdirs, $GUI_DISABLE)
GUICtrlSetState($option_assumedir, $GUI_DISABLE)
GUICtrlSetState($option_overwrite, $GUI_DISABLE)
GUICtrlSetState($option_errorcontinue, $GUI_DISABLE)
GUICtrlSetState($option_verify, $GUI_DISABLE)
GUICtrlSetState($option_noname, $GUI_DISABLE)
GUICtrlSetState($option_encryptedfiles, $GUI_DISABLE)
GUICtrlSetState($option_copyhands, $GUI_DISABLE)
GUICtrlSetState($option_copyarchoff, $GUI_DISABLE)
GUICtrlSetState($option_copyarchon, $GUI_DISABLE)
GUICtrlSetState($option_restartablemode, $GUI_DISABLE)
GUICtrlSetState($option_unbuffered, $GUI_DISABLE)
GUICtrlSetState($Sourcebtn, $GUI_DISABLE)
GUICtrlSetState($Destbtn, $GUI_DISABLE)
GUICtrlSetState($copy, $GUI_DISABLE)
;run the cmd
RunWait(@ComSpec & " /c " & $cmdprep, "", @SW_SHOW)
;completed message
$sourcesize = DirGetSize(GUICtrlRead($SourceInput), 1)
$destsize = DirGetSize(GUICtrlRead($DestInput), 1)
;check sizes match
If $destsize[0] = $sourcesize[0] Then
MsgBox(64, "Xcopy Gui", "'" & $source & "' Copied to '" & $destination & "' Successfully.", 3)
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Completed|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
Else
MsgBox(64, "Xcopy Gui", "'" & $source & "' Copied to '" & $destination & "' , but final sizes do not match.", 3)
$tCur = _Date_Time_GetSystemTime()
GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Completed, but sizes do not match|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
 
EndIf
 
;re-enable the options
GUICtrlSetState($Option_subdirs, $GUI_ENABLE)
GUICtrlSetState($option_assumedir, $GUI_ENABLE)
GUICtrlSetState($option_overwrite, $GUI_ENABLE)
GUICtrlSetState($option_errorcontinue, $GUI_ENABLE)
GUICtrlSetState($option_verify, $GUI_ENABLE)
GUICtrlSetState($option_noname, $GUI_ENABLE)
GUICtrlSetState($option_encryptedfiles, $GUI_ENABLE)
GUICtrlSetState($option_copyhands, $GUI_ENABLE)
GUICtrlSetState($option_copyarchoff, $GUI_ENABLE)
GUICtrlSetState($option_copyarchon, $GUI_ENABLE)
GUICtrlSetState($option_restartablemode, $GUI_ENABLE)
If @OSVersion <> "WIN_XP" Then
GUICtrlSetState($option_unbuffered, $GUI_ENABLE)
EndIf
GUICtrlSetState($Sourcebtn, $GUI_ENABLE)
GUICtrlSetState($Destbtn, $GUI_ENABLE)
GUICtrlSetState($copy, $GUI_ENABLE)
 
 
 
EndSwitch
WEnd

I've compiled it in 32bit and 64bit version contained in this rar

Feedback would be nice :graduated:

Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites



I was just getting ready to create a small application like this, but figured I should look around the forum first before starting on my project.

I like the look and ease of use, but did have to make a slight modification for my first test run.

I'm not sure which version of XCOPY you may be running on your workstation, but my version is 5.1.2600.

Which does not support the "/J" switch you have for the $unbuffered variable. "Copies using unbuffered I/O. Recommended for very large files"

All of the other switches you use exist, so I don't imagine any issues there.

Once I get a chance I may run it through some more tests.

Thanks for sharing!


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites

It appears that the /j switch is only usable under Windows 7 and/or Vista, my Win7 box has version 6.1.7600 while my XP machine has 5.1.2600. I'm guessing the version number corresponds to the Windows version number that it's running on.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I had that feeling and was going to try it out on my Win7 when I get home. Whole network is XP and can't get my hands on Win7 here at work, yet...


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites

It wouldn't be hard to modify the code to include a check of the OS version and if it's XP or lower don't show that check box, or use that option.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yep, working fine on my Win7 X64.

I would follow along the lines as what BrewManNH stated.

If it were me, I would either do an OS Version check on launch, or XCOPY version on launch, and then simply uncheck and disable that checkbox if the end-user has the wrong version.


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

My fault there, never thought that XCopy had improved from the XP ver, I've added in this OS check

If @OSVersion = "WIN_XP" Then
    $option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
    GUICtrlSetState(-1, $GUI_UNCHECKED)
    GUICtrlSetState(-1, $GUI_DISABLE)
Else
    $option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
EndIf

and recompiled and updated the .rar and the source code in the first post. :graduated:, if you find anymore things just let me know

Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

Viva,

Thank you for providing this GUI for xcopy. :graduated:

The interface is nice and functional.

Pause WORKS !!!

When testing the v2 version with all the default options found the following, which I think is of interest best, I think.

- When selecting the destination, it does not check whether the destination has enough space. (DriveSpaceFree ("path"))

- When copying to a destination out of space, the program ends stating that the copy was successful, I think be worth checking the return of xcopy. (_ProcessExitCode ($ Pid))

- While running a task, options must be disabled.

- While running, if you close the window xcopy, the program reports that the job went well.

When i get a chance I will see the code, and it may be that you will notice some possible improvements.

Again,

Thanks for sharing

Sincerely

Nuno Borges ;)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@Nuno, Thanks for the feedback, I'll get on and start implementing the things you have highlighted, and I'll post back once I have something to show

wrote in the to disabled the options when running a task, and re-enable them once completed (original source updated), but I've not updated the .rar yet

todo

calculate size of source files/folder

check size of destination for enough free space

monitor/result code of xcopy PID for early closure.

possible todo's

hide xcopy cmd prompt

use progress bar for remaining bytes/mb's to be copied, negating the need to check for early xcopy.exe closure.

Thanks again :graduated:

RichE

Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

added source size check, destination is disabled until source is selected, destination freespace check added, will not enable the "Proceed with copy" unless there is enough free space.

All gui controls are disabled on task execution.

I've updated the source code ^^ and also the .rar link ^^


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

Instead of disabling and then reenabling all of the controls during the copy, you might want to try using GUISetState(@SW_DISABLE) and @SW_ENABLE, that will disable the whole GUI instead of each control one at a time. Also, the method you use to find the destination freespace takes a LONG time, you should use DriveSpaceFree instead of DirGetSize because that checks to see if the DRIVE has the space available rather than if a directory does. The code below has the changes made to your original code that includes these changes, try them both and see which works better for you.

#cs ----------------------------------------------------------------------------
 AutoIt Version: 3.3.6.1
 Author:         Richard Easton#include <ButtonConstants.au3>
 Script Function:
 XCopy GUI Version 2
 Feature:
 Hidden Cmd window with in gui CMD Progress.
 More checkbox functions
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
$Xcopy_GUI = GUICreate("XCopy GUI Version2", 834, 600, -1, -1)
;target information
$Target_Information = GUICtrlCreateGroup(" Target Information ", 8, 16, 817, 73)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Source", 16, 40, 38, 17)
$SourceInput = GUICtrlCreateInput("", 80, 37, 577, 21)
GUICtrlSetColor(-1, 0xF0F0F0)
GUICtrlSetBkColor(-1, 0x008080)
$Sourcebtn = GUICtrlCreateButton("Browse to Source", 664, 36, 153, 23)
GUICtrlCreateLabel("Destination", 16, 64, 57, 17)
$DestInput = GUICtrlCreateInput("", 80, 60, 577, 21)
GUICtrlSetBkColor(-1, 0x1B80E4)
$Destbtn = GUICtrlCreateButton("Browse to Destination", 664, 60, 153, 21)
GUICtrlSetState($Destbtn, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;xcopy options
$Xcopy_Options = GUICtrlCreateGroup(" XCopy Options ", 8, 96, 817, 137)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Option_subdirs = GUICtrlCreateCheckbox("Copy directories and  subdirectories, including empty ones.", 16, 112, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_assumedir = GUICtrlCreateCheckbox("If Destination does not exist, assume that it is a directory.", 16, 131, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_overwrite = GUICtrlCreateCheckbox("Suppress prompting to confirm overwrite. (will overwrite if checked)", 16, 151, 400, 17)
$option_errorcontinue = GUICtrlCreateCheckbox("Continue even if an error occurs.", 16, 172, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_verify = GUICtrlCreateCheckbox("Verifies the size of each new file.", 16, 191, 400, 17)
$option_noname = GUICtrlCreateCheckbox("Does not display file names while copying.", 16, 210, 400, 17)
$option_encryptedfiles = GUICtrlCreateCheckbox("Copies encrypted files to destination, that does not support it.", 424, 210, 400, 17)
$option_copyhands = GUICtrlCreateCheckbox("Copies hidden and system files.", 424, 191, 400, 17)
$option_copyarchoff = GUICtrlCreateCheckbox("Only copies files with the archive bit set, turning it off after.", 424, 112, 400, 17)
$option_copyarchon = GUICtrlCreateCheckbox("Only copies files with the archive bit set, leaving it on after.", 424, 131, 400, 17)
$option_restartablemode = GUICtrlCreateCheckbox("Copies networked files in restartable mode.", 424, 151, 400, 17)
If @OSVersion = "WIN_XP" Then
 $option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
 GUICtrlSetState(-1, $GUI_UNCHECKED)
 GUICtrlSetState(-1, $GUI_DISABLE)
Else
 $option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
 GUICtrlSetState(-1, $GUI_CHECKED)
EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1)
;progress pain
$Session_Progress = GUICtrlCreateGroup(" Session Progress ", 8, 240, 817, 321)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Progress = GUICtrlCreateListView("", 16, 256, 801, 292, -1, $LVS_EX_GRIDLINES)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;controls
$copy = GUICtrlCreateButton("Proceed with copy", 677, 568, 147, 25)
GUICtrlSetState($copy, $GUI_DISABLE)
_GUICtrlListView_AddColumn($Progress, "Description", 580, 0)
_GUICtrlListView_AddColumn($Progress, "Date/Time", 200, 0)
GUISetState(@SW_SHOW)
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Sourcebtn
   $source = FileSelectFolder("Select Source Folder", "", 1 + 2 + 4)
   If @error Then
    ;check to see if no folder has been selected
    MsgBox(48, "Source Folder", "no folder selected or dialogue cancelled", 5)
   Else
    ;update source input
    If $source = "computer" Then
     MsgBox(48, "Warning!", "Invalid Location selected", 5)
    Else
     GUICtrlSetData($SourceInput, $source, "")
     $tCur = _Date_Time_GetSystemTime()
     GUICtrlCreateListViewItem("Source Location Selected, checking size|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
     Sleep(500)
     $sourcesize = DirGetSize(GUICtrlRead($SourceInput), 1)
     $sourcesize = $sourcesize[0] /1024/2024
     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sourcesize = ' & $sourcesize & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
     If Round($sourcesize) < 1000 Then
      $tCur = _Date_Time_GetSystemTime()
      GUICtrlCreateListViewItem("Source directory size(Mb): " & Round($sourcesize) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
     Else
      $tCur = _Date_Time_GetSystemTime()
      GUICtrlCreateListViewItem("Source directory size(Gb): " & Round($sourcesize, 2) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
     EndIf
     GUICtrlSetState($Destbtn, $GUI_ENABLE)
    EndIf
   EndIf
  Case $Destbtn
   $destination = FileSelectFolder("Select Destination Folder", "", 1 + 2 + 4)
   ;read source location
   $source = GUICtrlRead($SourceInput)
   If @error Then
    ;check to see if no folder has been selected
    MsgBox(48, "Destination Folder", "no folder selected or dialogue cancelled", 5)
   ElseIf $source > "" Then
    ;check source and destination are the same, if they are display warning!
    If $destination = $source Then
     MsgBox(48, "Warning!", "Source and Destination cannot be the same!", 5)
    Else
     If $destination = "computer" Then
      MsgBox(48, "Warning!", "Invalid Location selected", 5)
     Else;update destination input
      GUICtrlSetData($DestInput, $destination, "")
      $tCur = _Date_Time_GetSystemTime()
      GUICtrlCreateListViewItem("Destination Location Selected, checking freespace|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
      If StringLen(GUICtrlRead($DestInput)) > 3 Then
       $destloc = StringLeft(GUICtrlRead($DestInput), 3)
;~     $destfreespace = DirGetSize($destloc, 1)
       $destfreespace = DriveSpaceFree($destloc)
       ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $destfreespace = ' & $destfreespace & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
      Else
;~     $destfreespace = DirGetSize(GUICtrlRead($DestInput), 1)
       $destfreespace = DriveSpaceFree($destloc)
      EndIf
      ;check for Mb or Gb
      If Round($destfreespace) < 1000 Then
       ;Check source is not bigger than destination
       If Round($destfreespace) < Round($sourcesize) Then
        MsgBox(48, "XCopy GUI", "There is not enough freespace on the destination to copy all data" & @CR & "Please choose another destination")
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Not enough freeSpace on Destination|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetData($DestInput, "", "")
       Else
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Destination FreeSpace(Mb): " & Round($destfreespace) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlCreateListViewItem("Sufficient freespace to do copy|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetState($copy, $GUI_ENABLE)
       EndIf
      Else
       If Round($destfreespace, 2) < Round($sourcesize, 2) Then
        MsgBox(48, "XCopy GUI", "There is not enough f`reespace on the destination to copy all data" & @CR & "Please choose another destination")
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Not enough freeSpace on Destination|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetData($DestInput, "", "")
       Else
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Destination FreeSpace(Mb): " & Round($destfreespace, 2) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlCreateListViewItem("Sufficient freespace to do copy|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetState($copy, $GUI_ENABLE)
       EndIf
      EndIf
     EndIf
    EndIf
   EndIf
  Case $copy
   ; cmd line for xcopy is
   ProgressOn("XCopy GUI", "Please Wait", "Checking options", -1, -1)
   ProgressSet(10, "Checking Options", "Please Wait")
   Sleep(2000)
   $subdirs = GUICtrlRead($Option_subdirs)
   $assumedirs = GUICtrlRead($option_assumedir)
   $overwrite = GUICtrlRead($option_overwrite)
   $errorcontinue = GUICtrlRead($option_errorcontinue)
   $verify = GUICtrlRead($option_verify)
   $noname = GUICtrlRead($option_noname)
   $encfiles = GUICtrlRead($option_encryptedfiles)
   $copyhands = GUICtrlRead($option_copyhands)
   $archoff = GUICtrlRead($option_copyarchoff)
   $archon = GUICtrlRead($option_copyarchon)
   $restartable = GUICtrlRead($option_restartablemode)
   $unbuffered = GUICtrlRead($option_unbuffered)
   ; 'XCOPY source destination /E /I /Y /C /V /Q /G /H /A /M /Z /J'
   If $subdirs = 1 Then
    $subdirs = "/E "
   Else
    $subdirs = ""
   EndIf
   If $assumedirs = 1 Then
    $assumedirs = "/I "
   Else
    $assumedirs = ""
   EndIf
   If $overwrite = 1 Then
    $overwrite = "/Y "
   Else
    $overwrite = ""
   EndIf
   If $errorcontinue = 1 Then
    $errorcontinue = "/C "
   Else
    $errorcontinue = ""
   EndIf
   If $verify = 1 Then
    $verify = "/V "
   Else
    $verify = ""
   EndIf
   If $noname = 1 Then
    $noname = "/Q "
   Else
    $noname = ""
   EndIf
   If $encfiles = 1 Then
    $encfiles = "/G "
   Else
    $encfiles = ""
   EndIf
   If $copyhands = 1 Then
    $copyhands = "/H "
   Else
    $copyhands = ""
   EndIf
   If $archoff = 1 Then
    $archoff = "/A "
    If $archon = 1 Then
     GUICtrlSetState($option_copyarchon, $GUI_UNCHECKED)
    EndIf
   Else
    $archoff = ""
   EndIf
   If $archon = 1 And $archoff = 4 Then
    $archon = "/M "
   Else
    $archon = ""
   EndIf
   If $restartable = 1 Then
    $restartable = "/Z "
   Else
    $restartable = ""
   EndIf
   If $unbuffered = 1 Then
    $unbuffered = "/J"
   Else
    $unbuffered = ""
   EndIf
   ProgressSet(30, "Options Set", "Please Wait")
   Sleep(2000)
   ProgressSet(40, "Checking Locations", "Please Wait")
   $source = GUICtrlRead($SourceInput)
   $destination = GUICtrlRead($DestInput)
   If $source = "" Or $destination = "" Then
    MsgBox(48, "Warning!", "There is a problem with one location", 5)
    Sleep(2000)
    ProgressOff()
   Else
    Sleep(2000)
    ProgressSet(50, "Source and Destination verified", "Please Wait")
    Sleep(2000)
   EndIf
   ProgressSet(80, "Preparing Command", "Please Wait")
   $cmdprep = 'Xcopy "' & $source & '" "' & $destination & '" ' & $subdirs & $assumedirs & $overwrite & $errorcontinue & $verify & $noname & $encfiles & $copyhands & $archoff & $archon & $restartable & $unbuffered
   ProgressSet(100, "Ready to go :D", "Checks Complete")
   Sleep(2000)
   ProgressOff()
   $tCur = _Date_Time_GetSystemTime()
   GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Started|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
   ;subdirs,assumedir,overwrite,errorcontinue,verify,noname,encryptedfiles,copyhands,copyarchoff,copyarchon,restartablemode,unbuffered
   ;disable the options
   GUISetState(@SW_DISABLE)
   #cs
   GUICtrlSetState($Option_subdirs, $GUI_DISABLE)
   GUICtrlSetState($option_assumedir, $GUI_DISABLE)
   GUICtrlSetState($option_overwrite, $GUI_DISABLE)
   GUICtrlSetState($option_errorcontinue, $GUI_DISABLE)
   GUICtrlSetState($option_verify, $GUI_DISABLE)
   GUICtrlSetState($option_noname, $GUI_DISABLE)
   GUICtrlSetState($option_encryptedfiles, $GUI_DISABLE)
   GUICtrlSetState($option_copyhands, $GUI_DISABLE)
   GUICtrlSetState($option_copyarchoff, $GUI_DISABLE)
   GUICtrlSetState($option_copyarchon, $GUI_DISABLE)
   GUICtrlSetState($option_restartablemode, $GUI_DISABLE)
   GUICtrlSetState($option_unbuffered, $GUI_DISABLE)
   GUICtrlSetState($Sourcebtn, $GUI_DISABLE)
   GUICtrlSetState($Destbtn, $GUI_DISABLE)
   GUICtrlSetState($copy, $GUI_DISABLE)
   #ce
   ;run the cmd
   RunWait(@ComSpec & " /c " & $cmdprep, "", @SW_SHOW)
   ;completed message
   $sourcesize = DirGetSize(GUICtrlRead($SourceInput), 1)
   $destsize = DirGetSize(GUICtrlRead($DestInput), 1)
   ;check sizes match
   If $destsize[0] = $sourcesize Then
    MsgBox(64, "Xcopy Gui", "'" & $source & "' Copied to '" & $destination & "' Successfully.", 3)
    $tCur = _Date_Time_GetSystemTime()
    GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Completed|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
   Else
    MsgBox(64, "Xcopy Gui", "'" & $source & "' Copied to '" & $destination & "' , but final sizes do not match.", 3)
    $tCur = _Date_Time_GetSystemTime()
    GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Completed, but sizes do not match|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
   EndIf
   ;re-enable the options
   #cs
   GUICtrlSetState($Option_subdirs, $GUI_ENABLE)
   GUICtrlSetState($option_assumedir, $GUI_ENABLE)
   GUICtrlSetState($option_overwrite, $GUI_ENABLE)
   GUICtrlSetState($option_errorcontinue, $GUI_ENABLE)
   GUICtrlSetState($option_verify, $GUI_ENABLE)
   GUICtrlSetState($option_noname, $GUI_ENABLE)
   GUICtrlSetState($option_encryptedfiles, $GUI_ENABLE)
   GUICtrlSetState($option_copyhands, $GUI_ENABLE)
   GUICtrlSetState($option_copyarchoff, $GUI_ENABLE)
   GUICtrlSetState($option_copyarchon, $GUI_ENABLE)
   GUICtrlSetState($option_restartablemode, $GUI_ENABLE)
   #ce
   GUISetState(@SW_ENABLE)
   If @OSVersion <> "WIN_XP" Then
    GUICtrlSetState($option_unbuffered, $GUI_ENABLE)
   EndIf
   GUICtrlSetState($Sourcebtn, $GUI_ENABLE)
   GUICtrlSetState($Destbtn, $GUI_ENABLE)
   GUICtrlSetState($copy, $GUI_ENABLE)
 EndSwitch
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewmanH, Thanks for the help, I thought about @sw_disable, but I also thought about hiding the gui completely and showing it afterwards, you way seems more efficient.

like they say, you learn something new everyday :graduated:, so thanks again for the tips

Regards

RichE


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

your changes for determining freespace worked really well, I changed @SW_DISABLE to @SW_HIDE so it completely hide the gui until the xcopy cmd prompt window has exited.

also corrected a typo for comparing the completed task sizes.

thanks agian for the help.

here's my updated code (including your code)

#cs ----------------------------------------------------------------------------
 AutoIt Version: 3.3.6.1
 Author:         Richard Easton
 Thanks to: BrewmanNH for the code help
 Script Function:  XCopy GUI Version 2
 #ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
$Xcopy_GUI = GUICreate("XCopy GUI Version2", 834, 600, -1, -1)
;target information
$Target_Information = GUICtrlCreateGroup(" Target Information ", 8, 16, 817, 73)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Source", 16, 40, 38, 17)
$SourceInput = GUICtrlCreateInput("", 80, 37, 577, 21)
GUICtrlSetColor(-1, 0xF0F0F0)
GUICtrlSetBkColor(-1, 0x008080)
$Sourcebtn = GUICtrlCreateButton("Browse to Source", 664, 36, 153, 23)
GUICtrlCreateLabel("Destination", 16, 64, 57, 17)
$DestInput = GUICtrlCreateInput("", 80, 60, 577, 21)
GUICtrlSetBkColor(-1, 0x1B80E4)
$Destbtn = GUICtrlCreateButton("Browse to Destination", 664, 60, 153, 21)
GUICtrlSetState($Destbtn, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;xcopy options
$Xcopy_Options = GUICtrlCreateGroup(" XCopy Options ", 8, 96, 817, 137)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Option_subdirs = GUICtrlCreateCheckbox("Copy directories and  subdirectories, including empty ones.", 16, 112, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_assumedir = GUICtrlCreateCheckbox("If Destination does not exist, assume that it is a directory.", 16, 131, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_overwrite = GUICtrlCreateCheckbox("Suppress prompting to confirm overwrite. (will overwrite if checked)", 16, 151, 400, 17)
$option_errorcontinue = GUICtrlCreateCheckbox("Continue even if an error occurs.", 16, 172, 400, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$option_verify = GUICtrlCreateCheckbox("Verifies the size of each new file.", 16, 191, 400, 17)
$option_noname = GUICtrlCreateCheckbox("Does not display file names while copying.", 16, 210, 400, 17)
$option_encryptedfiles = GUICtrlCreateCheckbox("Copies encrypted files to destination, that does not support it.", 424, 210, 400, 17)
$option_copyhands = GUICtrlCreateCheckbox("Copies hidden and system files.", 424, 191, 400, 17)
$option_copyarchoff = GUICtrlCreateCheckbox("Only copies files with the archive bit set, turning it off after.", 424, 112, 400, 17)
$option_copyarchon = GUICtrlCreateCheckbox("Only copies files with the archive bit set, leaving it on after.", 424, 131, 400, 17)
$option_restartablemode = GUICtrlCreateCheckbox("Copies networked files in restartable mode.", 424, 151, 400, 17)
If @OSVersion = "WIN_XP" Then
 $option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
 GUICtrlSetState(-1, $GUI_UNCHECKED)
 GUICtrlSetState(-1, $GUI_DISABLE)
Else
 $option_unbuffered = GUICtrlCreateCheckbox("Copies using unbuffered I/O. Recommended for very large files.", 424, 172, 400, 17)
 GUICtrlSetState(-1, $GUI_CHECKED)
EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1)
;progress pain
$Session_Progress = GUICtrlCreateGroup(" Session Progress ", 8, 240, 817, 321)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Progress = GUICtrlCreateListView("", 16, 256, 801, 292, -1, $LVS_EX_GRIDLINES)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;controls
$copy = GUICtrlCreateButton("Proceed with copy", 677, 568, 147, 25)
GUICtrlSetState($copy, $GUI_DISABLE)
_GUICtrlListView_AddColumn($Progress, "Description", 580, 0)
_GUICtrlListView_AddColumn($Progress, "Date/Time", 200, 0)
GUISetState(@SW_SHOW)
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Sourcebtn
   $source = FileSelectFolder("Select Source Folder", "", 1 + 2 + 4)
   If @error Then
    ;check to see if no folder has been selected
    MsgBox(48, "Source Folder", "no folder selected or dialogue cancelled", 5)
   Else
    ;update source input
    If $source = "computer" Then
     MsgBox(48, "Warning!", "Invalid Location selected", 5)
    Else
     GUICtrlSetData($SourceInput, $source, "")
     $tCur = _Date_Time_GetSystemTime()
     GUICtrlCreateListViewItem("Source Location Selected, checking size|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
     Sleep(500)
     $sourcesize = DirGetSize(GUICtrlRead($SourceInput), 1)
     $sourcesize = $sourcesize[0] /1024/2024
     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sourcesize = ' & $sourcesize & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
     If Round($sourcesize) < 1000 Then
      $tCur = _Date_Time_GetSystemTime()
      GUICtrlCreateListViewItem("Source directory size(Mb): " & Round($sourcesize) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
     Else
      $tCur = _Date_Time_GetSystemTime()
      GUICtrlCreateListViewItem("Source directory size(Gb): " & Round($sourcesize, 2) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
     EndIf
     GUICtrlSetState($Destbtn, $GUI_ENABLE)
    EndIf
   EndIf
  Case $Destbtn
   $destination = FileSelectFolder("Select Destination Folder", "", 1 + 2 + 4)
   ;read source location
   $source = GUICtrlRead($SourceInput)
   If @error Then
    ;check to see if no folder has been selected
    MsgBox(48, "Destination Folder", "no folder selected or dialogue cancelled", 5)
   ElseIf $source > "" Then
    ;check source and destination are the same, if they are display warning!
    If $destination = $source Then
     MsgBox(48, "Warning!", "Source and Destination cannot be the same!", 5)
    Else
     If $destination = "computer" Then
      MsgBox(48, "Warning!", "Invalid Location selected", 5)
     Else;update destination input
      GUICtrlSetData($DestInput, $destination, "")
      $tCur = _Date_Time_GetSystemTime()
      GUICtrlCreateListViewItem("Destination Location Selected, checking freespace|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
      If StringLen(GUICtrlRead($DestInput)) > 3 Then
       $destloc = StringLeft(GUICtrlRead($DestInput), 3)
       $destfreespace = DriveSpaceFree($destloc)
       ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $destfreespace = ' & $destfreespace & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
      Else
       $destfreespace = DriveSpaceFree($destloc)
      EndIf
      ;check for Mb or Gb
      If Round($destfreespace) < 1000 Then
       ;Check source is not bigger than destination
       If Round($destfreespace) < Round($sourcesize) Then
        MsgBox(48, "XCopy GUI", "There is not enough freespace on the destination to copy all data" & @CR & "Please choose another destination")
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Not enough freeSpace on Destination|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetData($DestInput, "", "")
       Else
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Destination FreeSpace(Mb): " & Round($destfreespace) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlCreateListViewItem("Sufficient freespace to do copy|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetState($copy, $GUI_ENABLE)
       EndIf
      Else
       If Round($destfreespace, 2) < Round($sourcesize, 2) Then
        MsgBox(48, "XCopy GUI", "There is not enough f`reespace on the destination to copy all data" & @CR & "Please choose another destination")
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Not enough freeSpace on Destination|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetData($DestInput, "", "")
       Else
        $tCur = _Date_Time_GetSystemTime()
        GUICtrlCreateListViewItem("Destination FreeSpace(Mb): " & Round($destfreespace, 2) & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlCreateListViewItem("Sufficient freespace to do copy|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
        GUICtrlSetState($copy, $GUI_ENABLE)
       EndIf
      EndIf
     EndIf
    EndIf
   EndIf
  Case $copy
   ; cmd line for xcopy is
   ProgressOn("XCopy GUI", "Please Wait", "Checking options", -1, -1)
   ProgressSet(10, "Checking Options", "Please Wait")
   Sleep(2000)
   $subdirs = GUICtrlRead($Option_subdirs)
   $assumedirs = GUICtrlRead($option_assumedir)
   $overwrite = GUICtrlRead($option_overwrite)
   $errorcontinue = GUICtrlRead($option_errorcontinue)
   $verify = GUICtrlRead($option_verify)
   $noname = GUICtrlRead($option_noname)
   $encfiles = GUICtrlRead($option_encryptedfiles)
   $copyhands = GUICtrlRead($option_copyhands)
   $archoff = GUICtrlRead($option_copyarchoff)
   $archon = GUICtrlRead($option_copyarchon)
   $restartable = GUICtrlRead($option_restartablemode)
   $unbuffered = GUICtrlRead($option_unbuffered)
   ; 'XCOPY source destination /E /I /Y /C /V /Q /G /H /A /M /Z /J'
   If $subdirs = 1 Then
    $subdirs = "/E "
   Else
    $subdirs = ""
   EndIf
   If $assumedirs = 1 Then
    $assumedirs = "/I "
   Else
    $assumedirs = ""
   EndIf
   If $overwrite = 1 Then
    $overwrite = "/Y "
   Else
    $overwrite = ""
   EndIf
   If $errorcontinue = 1 Then
    $errorcontinue = "/C "
   Else
    $errorcontinue = ""
   EndIf
   If $verify = 1 Then
    $verify = "/V "
   Else
    $verify = ""
   EndIf
   If $noname = 1 Then
    $noname = "/Q "
   Else
    $noname = ""
   EndIf
   If $encfiles = 1 Then
    $encfiles = "/G "
   Else
    $encfiles = ""
   EndIf
   If $copyhands = 1 Then
    $copyhands = "/H "
   Else
    $copyhands = ""
   EndIf
   If $archoff = 1 Then
    $archoff = "/A "
    If $archon = 1 Then
     GUICtrlSetState($option_copyarchon, $GUI_UNCHECKED)
    EndIf
   Else
    $archoff = ""
   EndIf
   If $archon = 1 And $archoff = 4 Then
    $archon = "/M "
   Else
    $archon = ""
   EndIf
   If $restartable = 1 Then
    $restartable = "/Z "
   Else
    $restartable = ""
   EndIf
   If $unbuffered = 1 Then
    $unbuffered = "/J"
   Else
    $unbuffered = ""
   EndIf
   ProgressSet(30, "Options Set", "Please Wait")
   Sleep(2000)
   ProgressSet(40, "Checking Locations", "Please Wait")
   $source = GUICtrlRead($SourceInput)
   $destination = GUICtrlRead($DestInput)
   If $source = "" Or $destination = "" Then
    MsgBox(48, "Warning!", "There is a problem with one location", 5)
    Sleep(2000)
    ProgressOff()
   Else
    Sleep(2000)
    ProgressSet(50, "Source and Destination verified", "Please Wait")
    Sleep(2000)
   EndIf
   ProgressSet(80, "Preparing Command", "Please Wait")
   $cmdprep = 'Xcopy "' & $source & '" "' & $destination & '" ' & $subdirs & $assumedirs & $overwrite & $errorcontinue & $verify & $noname & $encfiles & $copyhands & $archoff & $archon & $restartable & $unbuffered
   ProgressSet(100, "Ready to go :D", "Checks Complete")
   Sleep(2000)
   ProgressOff()
   $tCur = _Date_Time_GetSystemTime()
   GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Started|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
   ;disable the options
   GUISetState(@SW_HIDE)
 
   ;run the cmd
   RunWait(@ComSpec & " /c " & $cmdprep, "", @SW_SHOW)
   ;completed message
   $sourcesize = DirGetSize(GUICtrlRead($SourceInput), 1)
   $destsize = DirGetSize(GUICtrlRead($DestInput), 1)
   ;check sizes match
   If $destsize[0] = $sourcesize[0] Then
    MsgBox(64, "Xcopy Gui", "'" & $source & "' Copied to '" & $destination & "' Successfully.", 3)
    $tCur = _Date_Time_GetSystemTime()
    GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Completed|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
   Else
    MsgBox(64, "Xcopy Gui", "'" & $source & "' Copied to '" & $destination & "' , but final sizes do not match.", 3)
    $tCur = _Date_Time_GetSystemTime()
    GUICtrlCreateListViewItem("Xcopy from '" & $source & "' to '" & $destination & "' Completed, but sizes do not match|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Progress)
   EndIf
   ;re-enable the options
 
   GUISetState(@SW_SHOW)
   If @OSVersion <> "WIN_XP" Then
    GUICtrlSetState($option_unbuffered, $GUI_ENABLE)
   EndIf
   GUICtrlSetState($Sourcebtn, $GUI_ENABLE)
   GUICtrlSetState($Destbtn, $GUI_ENABLE)
   GUICtrlSetState($copy, $GUI_ENABLE)
 EndSwitch
WEnd

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

I'm glad I could help, the GUI idea you came up with was very useful for me as I have to copy things back and forth on my network drives a lot.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes, I shunt data around our network, and whilst there are windows based applications, I've alway found xcopy the most reliable, so I wrote this GUI to save me having to do xcopy /? to get the correct syntax for cmd line.

So if anyone finds it useful then I'm glad to share.

I've added a thanks to you into the source code.


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

did a minor re-calcualtion to determine mb or gb on destination drive freespace, added a splash screen, and created an inno installer for x86 and x64 version, both available for download via my website (saves autoit's site bandwidth).

thanks again to everyone who helped with the recoding :graduated:

Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

Viva,

For testing, I think it would be useful hast a version without requiring installation, and perhaps without upx.

Based on your post # 13, and the default options:

steps:

1 - Source: C: \ windows

2 - Destination C: \

Program exits.

another:

- Browse to Destination

- In the window of choice, cancel

Program exits.

PS: Do you know cmd Robocopy?

Best regards

:graduated:

Share this post


Link to post
Share on other sites

PS: Do you know cmd Robocopy?

If you're looking for a GUI for RoboCopy, there is one already, Microsoft has created it for most versions of RoboCopy.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

If you're looking for a GUI for RoboCopy, there is one already, Microsoft has created it for most versions of RoboCopy.

Viva,

Excuse me for not having addressed the issue of Robocopy, it was for the RichE, and put the question to think that for what it is in principle to use xcopy, robocopy can bring you the most advantages.

hug

Edited by NunoBorges

Share this post


Link to post
Share on other sites

Although Robocopy isn't included with Windows XP, you'd have to download it separately, xcopy has been included with every version of DOS and Windows since probably DOS 3. It also is still included with Windows 7, so some people are still using it in place of RoboCopy. I tend to use both myself, as RoboCopy works better on Win Vista/7 when copying folders with junctions in them.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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

  • Similar Content

    • vindicta
      By vindicta
      Hello Everyone,
      Please pardon my noobiness. I am working on backup restore script where a progress bar is required. I have tried using following code which works fine with folders but not really with single file because robocopy
      Func CopyFolder($srcDir, $destDir, $part) ;======> $part shows whats being copied (e.g. Desktop, Documents etc.) If StringRight($srcDir, 1) = "\" Then $srcDir = StringLeft($srcDir, StringLen($srcDir) - 1) If Not FileExists($destDir) Then DirCreate($destDir) $srcSize = DirGetSize($srcDir, $DIR_EXTENDED) $1_percent = $srcSize[0] / 100 $cmd = 'C:\Windows\System32\robocopy.exe "' & $srcDir & '" "' & $destDir & '" /E /Z /XO /XX /FFT /XJ /NDL /NJH /FP /ETA /NP /V /R:10 /W:5 /LOG+:"' & $logFile & '" /XF desktop.ini thumbs.db' Run(@ComSpec & " /c " & $cmd, "", @SW_HIDE) Do Sleep(300) Until ProcessExists("robocopy.exe") ProgressOn($part, $1_percent & "%", "", 0, 0, 16) Do $destSize = DirGetSize($destDir, $DIR_EXTENDED) ProgressSet(Round($destSize[0] / $1_percent, 2), Round($destSize[0] / (1024 * 1024), 2) & " MB of " & Round($srcSize[0] / (1024 * 1024), 2) & " MB copied", Round($destSize[0] / $1_percent, 2) & "%") Sleep(200) Until ProcessExists("robocopy.exe") = 0 ProgressOff() FileWriteLine($logFile, @CRLF & @CRLF) EndFunc ;==>CopyFolder Part of the problem is that I need to generate logs of files being copied. One particular problem is firefox profile directory. the directory is named as oi3jdslk.default or asdwdx.new and I need to copy places.sqlite from this directory.
      Xcopy manages to copy FROM this directory but not TO this directory because of wildcards
      Then I came across this neat script 
      Func CopyFile($fromFile, $todirectory) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($todirectory).CopyHere($fromFile, $FOF_RESPOND_YES) EndFunc ;==>CopyFile It helped me copy other single files but not the one required from firefox profile folder. Here is how I am trying to process that
      $path = @UserProfileDir & "\AppData\Roaming\Mozilla\Firefox\" & $ffDir & "\places.sqlite" CopyFile($path, $BUFolder & "Mozilla") ;===> $BUFolder = "E:\" & @username & " - Backup\" #cs ====================================================== $ffDir is another variable derived from this function. This variable is the gets the default firefox profile to copy places.sqlite from $ffDir is returned as Profiles\xbsen2s.default (Firefox randomizes the profile directory for extra security(?). At least that's what they say. #ce ====================================================== Func FFProfile() Local $iniFile = @UserProfileDir & "\AppData\Roaming\Mozilla\Firefox\profiles.ini" Local $ddNumber Local $ddLine Local $Line If FileExists($iniFile) Then FileOpen($iniFile, 0) For $i = 1 To _FileCountLines($iniFile) $Line = FileReadLine($iniFile, $i) If StringInStr("DEFAULT=1", $Line) Then $ddNumber = $i - 1 ExitLoop ElseIf StringInStr("Name=default", $Line) Then $ddNumber = $i + 2 EndIf Next $ddLine = FileReadLine($iniFile, $ddNumber) $ffDir = StringReplace(StringTrimLeft($ddLine, 5), "/", "\") $ffInstall = 1 Else $ffInstall = 0 EndIf FileClose($iniFile) EndFunc ;==>FFProfile I really like how natural the progress bar from second copy script look like and would like to keep the progress bar uniform across the program. I am willing to learn if anyone can point me in right direction and help me achieve this.

      Any help is highly appreciated!!
    • WannaBeGut
      By WannaBeGut
      Hello,
      I just wrote a script that should copy data into my cloud using xcopy (cmd), but I want the Status Bar I have in my GUI to change it's text like that:
      working. -> working.. -> working... -> working. ...
      I would also like to make a button which interrupts xcopy (simply closing it should do the trick), but I don't know how to call ProcessClose("xcopy.exe") using a button, while I'am waiting for RunWait to finish.
      Example:
      $command = 'xcopy "' & @DesktopDir & '\text.txt"' & ' "\\ADMIN-CLOUD\private\" /EECHIY' $SW_STATE = @SW_HIDE RunWait(@ComSpec & " /c " & '"' & $command & '"', @DesktopDir, $SW_State) Please tell me if you need any further information! 
    • Tim H.
      By Tim H.
      From within an AutoIt Script, I'm trying to use psexec with system authority to copy files from one place on a remote machine to another. When I issue the necessary command outside of the script (at a command prompt), the command executes properly. Here's the exact one-line command:

      psexec \\vmhartlti01 -s XCOPY "C:\temp\hs\Hyperspace POC.lnk" "C:\Documents and Settings\All Users\Application Data\Landesk\ManagementSuite\Launchpad\Dept Apps\" /Y

      When I try to run the exact same command from within an AutoIt Script, an XCOPY parse error 4 flashes up for a millisecond in the console and the command fails. The command appears to be formed properly in the message box popup.


      $cmd = 'psexec \\vmhartlti01 -s XCOPY "C:\temp\hs\Hyperspace POC.lnk" "C:\Documents and Settings\All Users\Application Data\Landesk\ManagementSuite\Launchpad\Dept Apps\" /Y' MsgBox(4096, "test", $cmd) $XCopyStatus = Run($cmd, "c:\temp")

      The Run command returns the XCOPY PID rather than zero, further obfuscating the problem. I've been working on this for a while now and I think I must be missing something. Does anyone see the problem?

      Thanks for your help.