3 posts in this topic
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 / 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 / $1_percent, 2), Round($destSize / (1024 * 1024), 2) & " MB of " & Round($srcSize / (1024 * 1024), 2) & " MB copied", Round($destSize / $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!!
Hi I need your help
I need download backup from 200 remote pc. I calculate that I can download 20 backups in one time. I need to create loop, take localizations from txt file and start 20 downloads in one time (i want use ShellExecute and robocopy), after finish one from running 20 take another localizations from txt file until localizations finish. And I need trigger if is 7:00 pause script. I hope you know what I mean
Many thanks for help, sorry for my english.
This is what I got:
#include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <Array.au3> #include <Date.au3> Local $targets = @ScriptDir& "\targets.txt" Local $log_name = "\autoit.log" MsgBox($MB_SYSTEMMODAL, "", "start copy", 1) Example() Func Example() If Not FileExists($targets) Then MsgBox($MB_SYSTEMMODAL, "", "The file targets.txt - doesn't exist!") Exit EndIf FileOpen($targets, 0) Global $arr ReDim $arr[_FileCountLines($targets)+1] For $i = 1 to _FileCountLines($targets) $line = FileReadLine($targets, $i) $arr[$i] = $line ; Check if is online Local $iPing = Ping($arr[$i], 250) If $iPing Then ; ONLINE $rc = FileCopy("\\"&$arr[$i]&"\e$\backup\", @ScriptDir&"\downloads\"&$arr[$i]&"\", $FC_CREATEPATH) If $rc = 0 Then _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" ONLINE error") Else _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" ONLINE done") EndIf Else ;OFFLINE _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" OFFLINE") EndIf Next EndFunc ;==>Example MsgBox($MB_SYSTEMMODAL, "", "Finish downloads backups") Exit
Hope you're doing great.
Well, I'm writing a script that allows our Service Desk to clean several temp folder as a first diagnostic.
Indeed, the agent in charge of the issue will have to choose what to clean (web browsers temp folders, some windows one etc...)
I added a progress bar to see the current state of the script but if I select more than one checkbox, it seems that the counting is not done properly and is directly filled at 100% (when at leat 2 boxes are checked) and I don"t get the final message saying that all is done, especially for if the last box is checked.
But if I launch the process with only one checkbox checked,it's working...
I've enclosed the au3 files for you because posting them in this post would be... unreadable lol. So you can maybe do some tests as well.
I'm pretty sure the code can be optimized (a lot ) and that there is a much better way to achieve what I want the script to be.
Maybe can someone can give me a hand over here.
Thanks in advance.
TinyBackupBox : Do a Backup of folders you want to a local/external drive/directory by using Robocopy.
A Big Thank to Yashield for TVExplorer.au3 and WinApiEx.au3
Includes needed : >TVExplorer.au3 and >WinApiEx.au3
* Left Treeview :
Check all folders Checkboxes you want to backup.
Hold Shift key when clicking a first child Checkbox will check all other child Checkboxes.
A right click on a parent item will uncheck all his child Checkboxes.
* Right Treeview :
A left click for select Backup Directory.
A right click menu on an item for create a new sub-folder which you can give the name you want.
This new sub-folder will be created and added as child item of the item you have right clicked.
* Start Button :
A Click on Start Button will start backup normally.
Hold Shift key when clicking it will start backup on Idle Mode.
Idle Mode is used for start or resume backup after a period of user inactivity (that you can set by tray menu)
and will pause current backup if not idle.
* Stop Button :
A click on Stop Button will Pause backup, and any changes will affect the backup when resume it.
You can resume a current backup by Re-clicking Start Button.
Hold Shift key when clicking Stop Button will totally Cancel current backup.
In Idle mode Stop Button is inactive until you Hold Shift key and click for Cancel current backup.
* Refresh Button :
A Click will refresh both treeviews and set them to the previous selections you have done.
Hold Shift key when clicking it will refresh both treeview and set them to the root.
* Tray Menu :
By Default Robocopy copy only new files,
so i add the possibility to
_ delete previous existing dir.
_ delete destination files and dirs that no longer exists in source.
_ Preserve all Attributes.
_ Show Robocopy Console window.
_ Set Idle Time Delay.
_ Open Backup Dir.
Update of 2011-12-21
Previous downloads : 103
source and executable are available in the Download Section
minimalist but handy !
Hope you like it !
And do not forget to create backup periodically !
I am trying to add the following parameters to Robocopy embedded in an the Autoit script below: /S /COPY:DT /R:4 /LOG+:"C:Script.log"
Any suggestions how to add it?
Thanks in advance!
RunWait(@ComSpec & ' /k ' & 'robocopy.exe "' & $SR1 & '" "' & $DS1 & '" ' & $PLC, @SystemDir)