teodoric666 Posted March 27 Share Posted March 27 (edited) hello it's still my discoveries autoit I would like to save the directory "MY DOCUMENTS" without the subfolders my images, my videos, my music. I use a robocopy script which is not mine but found here (-https://mgxp.blogspot.com/2016/06/robobackup7z-autoit-script-to-backup.html) I don't know if I'm allowed to post a link ? the backup directory is created but the copy is not good thanks in advance #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <Date.au3> $date = @MDAY & "-" & @MON $today = @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC DirCreate("D:\" & $date & '.\Mes Documents') Local $dest = "D:\" & $date & ".\Mes Documents\" $excludeFolders = ("@MyDocumentsDir\Ma musique") $excludeFolders = ("@MyDocumentsDir\Mes images") $excludeFolders =("@MyDocumentsDir\Mes videos") $source = '"' & (@UserProfileDir & "\Documents") & '"' $dest = ("D:\" &($date) & 'Documents') RunWait(@ComSpec & " /c ROBOCOPY " & $source & " " & $dest & _ " /MIR /R:2 " & " /TEE /XF desktop.ini", @ScriptDir, @SW_MINIMIZE) Sleep(2000) If @error Then MsgBox(2,"Erreur", "Une erreur s'est produite lors de la sauvegarde.") Else MsgBox(0,"Succès", "La sauvegarde a été effectuée avec succès.") EndIf Exit Edited March 27 by teodoric666 Link to comment Share on other sites More sharing options...
Nine Posted March 27 Share Posted March 27 Hello @teodoric666 58 minutes ago, teodoric666 said: it's still my discoveries autoit When you post code, please use the method described in the link. You can now edit your post, go back to your post and use the ... in the upper right to do so. 1 hour ago, teodoric666 said: I don't know if I'm allowed You should take the time to read forum rules. In there you will find all you should know of what it is allowed and what is not. 1 hour ago, teodoric666 said: I would like to save the directory Before embarking in coding, you should take a moment to plan your algorithmic approach. Once you start coding, you should be able to debug your code, there is a _Debug UDF, that can help you in your process of finding a solution. Now dropping a bunch of code to us to rewrite it so it will work for you, is definitely not the best way to learn how to program with AutoIt. Since you are new to AutoIt and you may not be familiar to all its intrinsic, I would recommend to use AutoIt functions (as far as possible) instead of relying on external programs. In your case, you may want to look at _FileListToArray or _FileListToArrayRec (which has a mask to exclude folders). Having a list of folders to copy into an array will help you to understand what is going on. Use _ArrayDisplay to read the content of an array. Finally look at DirCopy to perform the actual copy/backup of your folders. teodoric666 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Andreik Posted March 27 Share Posted March 27 (edited) Use /XD to exclude certain directories. And this $excludeFolders = ("@MyDocumentsDir\Ma musique") should be: $excludeFolders = @MyDocumentsDir & "\Ma musique" Also you overwrite $excludeFolders so after this: $excludeFolders = ("@MyDocumentsDir\Ma musique") $excludeFolders = ("@MyDocumentsDir\Mes images") $excludeFolders =("@MyDocumentsDir\Mes videos") $excludeFolders contains the last assignment. You have also some inconsistencies: DirCreate("D:\" & $date & '.\Mes Documents') $dest = ("D:\" &($date) & 'Documents') What exactly it is de destination here? #RequireAdmin $sDate = @MDAY & "-" & @MON $sToday = @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC $sSource = '"' & @UserProfileDir & '\Documents"' $sDestination = '"D:\' & $sDate & '\Documents"' If Not FileExists($sDestination) Then DirCreate($sDestination) Local $sExclude = ' /XD ' $sExclude &= ' "' & @MyDocumentsDir & '\My Music"' $sExclude &= ' "' & @MyDocumentsDir & '\My Pictures"' $sExclude &= ' "' & @MyDocumentsDir & '\My Videos"' RunWait(@ComSpec & " /c ROBOCOPY " & $sSource & " " & $sDestination & " /MIR /R:2 /TEE /XF desktop.ini" & $sExclude, @ScriptDir, @SW_MINIMIZE) If @error Then MsgBox(0x10, "Erreur", "Une erreur s'est produite lors de la sauvegarde.") Else MsgBox(0, "Succès", "La sauvegarde a été effectuée avec succès.") EndIf Edited March 27 by Andreik teodoric666 1 Link to comment Share on other sites More sharing options...
teodoric666 Posted March 27 Author Share Posted March 27 50 minutes ago, Nine said: Hello @teodoric666 When you post code, please use the method described in the link. You can now edit your post, go back to your post and use the ... in the upper right to do so. You should take the time to read forum rules. In there you will find all you should know of what it is allowed and what is not. Before embarking in coding, you should take a moment to plan your algorithmic approach. Once you start coding, you should be able to debug your code, there is a _Debug UDF, that can help you in your process of finding a solution. Now dropping a bunch of code to us to rewrite it so it will work for you, is definitely not the best way to learn how to program with AutoIt. Since you are new to AutoIt and you may not be familiar to all its intrinsic, I would recommend to use AutoIt functions (as far as possible) instead of relying on external programs. In your case, you may want to look at _FileListToArray or _FileListToArrayRec (which has a mask to exclude folders). Having a list of folders to copy into an array will help you to understand what is going on. Use _ArrayDisplay to read the content of an array. Finally look at DirCopy to perform the actual copy/backup of your folders. indeed you are right, I would like to learn quickly but for health reasons I will no longer have the time, that's why I try to get to the essentials thank you for helping me anyway and in addition to the language barrier Link to comment Share on other sites More sharing options...
teodoric666 Posted March 27 Author Share Posted March 27 47 minutes ago, Andreik said: Use /XD to exclude certain directories. And this $excludeFolders = ("@MyDocumentsDir\Ma musique") should be: $excludeFolders = @MyDocumentsDir & "\Ma musique" Also you overwrite $excludeFolders so after this: $excludeFolders = ("@MyDocumentsDir\Ma musique") $excludeFolders = ("@MyDocumentsDir\Mes images") $excludeFolders =("@MyDocumentsDir\Mes videos") $excludeFolders contains the last assignment. You have also some inconsistencies: DirCreate("D:\" & $date & '.\Mes Documents') $dest = ("D:\" &($date) & 'Documents') What exactly it is de destination here? thank you for helping me indeed I did so many tests lol that there is code that remains the destination directory is the directory d:\"date"\Documents #RequireAdmin $sDate = @MDAY & "-" & @MON $sToday = @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC $sSource = '"' & @UserProfileDir & '\Documents"' $sDestination = '"D:\' & $sDate & '\Documents"' If Not FileExists($sDestination) Then DirCreate($sDestination) Local $sExclude = ' /XD ' $sExclude &= ' "' & @MyDocumentsDir & '\My Music"' $sExclude &= ' "' & @MyDocumentsDir & '\My Pictures"' $sExclude &= ' "' & @MyDocumentsDir & '\My Videos"' RunWait(@ComSpec & " /c ROBOCOPY " & $sSource & " " & $sDestination & " /MIR /R:2 /TEE /XF desktop.ini" & $sExclude, @ScriptDir, @SW_MINIMIZE) If @error Then MsgBox(0x10, "Erreur", "Une erreur s'est produite lors de la sauvegarde.") Else MsgBox(0, "Succès", "La sauvegarde a été effectuée avec succès.") EndIf Link to comment Share on other sites More sharing options...
teodoric666 Posted March 27 Author Share Posted March 27 (edited) It seems to work I'm sharing it it must not be perfect but I'm moving forward thank you very much #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <Date.au3> $date = @MDAY & "-" & @MON $today = @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC Local $sourceFolder = @UserProfileDir & "\Documents" Local $backupFolder = "E:\" & $date & "\Documents" Local $logFile = @ScriptDir & "\robocopy.log" ; Vérifier si le dossier de sauvegarde existe, sinon le créer If Not FileExists($backupFolder) Then DirCreate($backupFolder) EndIf ; Exécuter Robocopy pour copier le contenu de la bibliothèque "Mes Documents" vers le dossier de sauvegarde Local $result = RunWait(@ComSpec & ' /c ROBOCOPY "' & $sourceFolder & '" "' & $backupFolder & '" /E /NP /R:2 /W:2 /LOG:' & $logFile, "", @SW_MINIMIZE) ; Vérifier si la sauvegarde a réussi en vérifiant le contenu du fichier journal If FileExists($logFile) Then If StringInStr(FileRead($logFile), "Succès") Then MsgBox($MB_ICONINFORMATION, "Sauvegarde réussie", "La sauvegarde de la bibliothèque 'Mes Documents' a été effectuée avec succès.") Else MsgBox($MB_ICONERROR, "Erreur lors de la sauvegarde", "Une erreur s'est produite lors de la sauvegarde de la bibliothèque 'Mes Documents'.") EndIf FileDelete($logFile) ; Supprimer le fichier journal après vérification ;Else ; MsgBox($MB_ICONERROR, "Erreur lors de la sauvegarde", "Une erreur s'est produite lors de la sauvegarde de la bibliothèque 'Mes Documents'.") EndIf Exit Edited March 27 by teodoric666 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now