random667 Posted April 16, 2008 Share Posted April 16, 2008 I am working on making a backup program and I would like to be able to backup files only if they have been changed since the last backup. I have been looking at DirCopy, but it only seems to have the option to overwrite or not. Also looked at FileGetTime to compare the files, but i am not sure if or how it could be used with DirCopy. Any ideas on how to do this? Thanks. It is really sad to see a family torn apart by something as simple as a pack of wolves. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 16, 2008 Moderators Share Posted April 16, 2008 I am working on making a backup program and I would like to be able to backup files only if they have been changed since the last backup.I have been looking at DirCopy, but it only seems to have the option to overwrite or not.Also looked at FileGetTime to compare the files, but i am not sure if or how it could be used with DirCopy.Any ideas on how to do this?Thanks.Could always do a FileGetSize() first with a conditional statement, if the two sizes aren't the same then then do an overwrite.You could also do a FileRead on both files then do a StringCompare if the string compare is <> or greater than 0 then do the over write.Then you could also do a checksum of the files (find around the forum) but I'd imagine this method (in autoit) to be much slower then the other two methods. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
random667 Posted April 16, 2008 Author Share Posted April 16, 2008 (edited) Could always do a FileGetSize() first with a conditional statement, if the two sizes aren't the same then then do an overwrite. You could also do a FileRead on both files then do a StringCompare if the string compare is <> or greater than 0 then do the over write. Then you could also do a checksum of the files (find around the forum) but I'd imagine this method (in autoit) to be much slower then the other two methods. I was afraid of that, and was hoping for just another flag that could be used with DirCopy. I have started making a script to go through all of the files and copy them one at a time and compare the files. This is what i have so far, and now my head hurts: #include <Array.au3> #include <File.au3> $NamesArray = StringSplit("Kathleen,FrontDesk,BackShop", ",") $PathsArray = StringSplit("Administrator\My Documents,Administrator\Favorites,Administrator\Application Data,All Users\Application Data,Administrator\Local Settings\Application Data", ",") For $i = 1 To UBound($NamesArray) - 1 Step + 1 For $j = 1 To UBound($PathsArray) - 1 Step + 1 $NetworkPath = "\\" & $NamesArray[$i] & "\Documents and Settings\" & $PathsArray[$j] & "\" $BackupPath = @MyDocumentsDir & "\Backup\" & $NamesArray[$i] & "\Documents and Settings\" & $PathsArray[$j] & "\" SaveFiles($NetworkPath, $BackupPath) CheckSubFolders($NetworkPath, $BackupPath) Next Next Func SaveFiles($NetworkPath, $BackupPath) $FileList = _FileListToArray($NetworkPath, "*", 1) For $k = 1 To UBound($FileList) - 1 Step + 1 $FileName = $FileList[$k] $File1Time = FileGetTime($NetworkPath & $FileName) $File2Time = FileGetTime($BackupPath & $FileName) If $File1Time <> $File2Time Then FileCopy($NetworkPath & $FileName, $BackupPath, 9) EndIf Next EndFunc ;==>SaveFiles Func CheckSubFolders($NetworkPath, $BackupPath) $SubFolderList = _FileListToArray($NetworkPath, "*", 2) For $k = 1 To UBound($SubFolderList) Step + 1 $SubFolderName = $SubFolderList[$k] $SubFolderPath = $NetworkPath & $SubFolderName & "\" $SubFolderList = _FileListToArray($FolderPath, "*", 2) SaveFiles($SubFolderPath, $BackupPath & $SubFolderName) Next EndFunc ;==>CheckSubFolders And i think this script will only go through the first set of files and folders, but not the sub-sub folders, but i haven't done any testing yet. Edited April 17, 2008 by random667 It is really sad to see a family torn apart by something as simple as a pack of wolves. Link to comment Share on other sites More sharing options...
randallc Posted April 17, 2008 Share Posted April 17, 2008 (edited) Hi, Probably easier to make your recursive file list to an array first (see link to _FileListToArrayNew), then just loop through your comparisons in one hit.. Best, Randall [PS - alternatively of course, just wrap xcopy with "/d"] Edited April 17, 2008 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
random667 Posted April 17, 2008 Author Share Posted April 17, 2008 I think i have it figured out now, my test worked anyway. For my test I made a folder called "TestFolder1" in the documents folder on my tv computer, inside "TestFolder1" i created a text file named Document1.txt and a folder named "TestFolder2", Inside "TestFolder2" i created a text file named Document2.txt and a folder named "TestFolder3", Inside "TestFolder3"... and so on, ten subfolders deep. This test code correctly copied all of the files into the correct folders and sub folders. Here is my working test script: #include <Array.au3> #include <File.au3> $NamesArray = "Tv\my documents\TestFolder1\" $NetworkPath = "\\Tv\my documents\TestFolder1\" $BackupPath = @MyDocumentsDir & "\Backup\" & $NamesArray SaveFiles($NetworkPath, $BackupPath) Func SaveFiles($NetworkPath, $BackupPath) $FileList = _FileListToArray($NetworkPath, "*", 1) For $k = 1 To UBound($FileList) - 1 Step + 1 $FileName = $FileList[$k] $File1Time = FileGetTime($NetworkPath & $FileName) $File2Time = FileGetTime($BackupPath & $FileName) If $File1Time <> $File2Time Then FileCopy($NetworkPath & $FileName, $BackupPath & $FileName, 9) EndIf Next CheckSubFolders($NetworkPath, $BackupPath) EndFunc ;==>SaveFiles Func CheckSubFolders($NetworkPath, $BackupPath) $SubFolderList = _FileListToArray($NetworkPath, "*", 2) For $k = 1 To UBound($SubFolderList)-1 Step + 1 $SubFolderName = $SubFolderList[$k] $SubFolderPath = $NetworkPath & $SubFolderName & "\" $SubBackupPath = $BackupPath & $SubFolderName & "\" $SubSubFolderList = _FileListToArray($SubFolderPath, "*", 2) SaveFiles($SubFolderPath, $SubBackupPath) Next EndFunc ;==>CheckSubFolders It is really sad to see a family torn apart by something as simple as a pack of wolves. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 17, 2008 Share Posted April 17, 2008 (edited) You could also use FileRead() If FileRead($FileA) <> FileRead($FileB) Then Now check the file size, time, and whatever else you want. Actually for my own backup, I just FileInstall("7za.exe") which is the command line version of 7Zip. That compresses my backups and by using the proper switches I can make it add to the backup only if the existing file has changed since the last backup. Sample on request only. Edited April 17, 2008 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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