33 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
is there a way to post into the "Usenet" with autoit ?
I didn't found any resources about it online.
"Nimps" is a regional slang word, which means easy or simple or basic and such.
I made a quick little script the other day to backup the visual studio project folder I was actively working on.
Thought I'd generalise it for use with the current active windows explorer folder.
When this script is running, and you hit "Ctrl and Shift and b", if a folder is open in windows explorer, it will copy the contents of it to your desired location ($GENERAL_BACKUP_FOLDER) including subfolders and its files and folders (so beware on deep directories)
If you have command line version of 7zip (7za.exe) you can choose to compress the folder rather than just copy it ($ZIP_FOLDER = True), or both I suppose.
Think that's all.
Reading the code should tell you anything else.
Oh, success or failure is indicated by a high or low frequency Beep().
#include <AutoItConstants.au3> #include <String.au3> HotKeySet("^+b", _Backup) ; ctrl and shift and b HotKeySet("!+b", _Exit) ; alt and shift and b Global Const $GENERAL_BACKUP_FOLDER = @ScriptDir & "Backup\" Global Const $ZIP_FOLDER = False Global Const $PATH_TO_7ZA = "D:\7za.exe" While 3 Sleep(300) WEnd ; High frequency beep if successful ; Low frequency beep if failed Func _Backup() Local $FOLDER_TO_BACKUP = "" Local $BACKUP_FOLDER = "" Local $CURRENT_BACKUP_FOLDER Local $WIN_TITLE = WinGetTitle("[Active]") Local $WIN_TEXT = WinGetText("[Active]") ; If text of window has no address, it is not a windows explorer If StringInStr($WIN_TEXT, "Address: ") Then Local $ACTIVE_EXPLORER_ADDRESS = _StringBetween($WIN_TEXT, "Address: ", @LF) If Not IsArray($ACTIVE_EXPLORER_ADDRESS) Then Beep(400, 150) Return @ScriptLineNumber EndIf $FOLDER_TO_BACKUP = $ACTIVE_EXPLORER_ADDRESS Else Return MsgBox(0, "Info", "The active window is not explorer") EndIf ; Check to see if root drive is backup source If StringRight($FOLDER_TO_BACKUP, 2) = ":\" Then $Answer = MsgBox(4, "Warning", "You are about to attempt to backup a whole disk" & @CRLF & "Are you sure?") If $Answer <> 6 Then Return EndIf ; Date and time to append to backup zip file or folder $APPEND = "_" & @YEAR & "_" & @MON & "_" & @MDAY & "_" & @HOUR & "_" & @MIN & "_" & @SEC Local $CURRENT_BACKUP_FOLDER = $GENERAL_BACKUP_FOLDER & $WIN_TITLE & $APPEND ; Zip to backup folder and return, 7za.exe required If $ZIP_FOLDER Then ; Buile command for 7za $command = $PATH_TO_7ZA & ' a ' & '"' & $GENERAL_BACKUP_FOLDER & $WIN_TITLE & $APPEND & '"' & '.zip ' & '"' & $FOLDER_TO_BACKUP & '"' $pid = Run($command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While ProcessExists($pid) Sleep(10) WEnd $out = StdoutRead($pid) ; Indicate if successfull If StringInStr($out, "Everything is Ok") Then Beep(700, 200) Return EndIf Beep(400, 200) Return EndIf ; Copy folder and beep when complete, no 7zip needed. Local $RTN = DirCopy($FOLDER_TO_BACKUP, $CURRENT_BACKUP_FOLDER, 1) ? Beep(700, 500) : Beep(400, 500) EndFunc ;==>_Backup Func _Exit() Exit EndFunc ;==>_Exit
I wanted to have a few lines that copy the whole registry into a file. I know that there is RegRead, but I don't want to type every single key into my code...
Any way of doing this easily? Filetype doesn't matter, as long as it isn't encrypted. A batch or exe would be okay, if it's in the same location on every PC. Doing this without admin permissions would be awesome too