OrthodoxyUSA Posted May 16, 2012 Share Posted May 16, 2012 Automated systems are using FTP to transfer very large 7z files over a WAN into a folder on your server.You would like to test each file (7z -t <filename>) as they are completed during the night.How will you know that the file is finished copying and free to be tested?Here's what I've been trying...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#include <Constants.au3>#Include <File.au3>#Include <Array.au3>#RequireAdminGlobal $FileGetList1[1000],$FileGetList2[1000]FileChangeDir("H:\CIS-NG")While 1FileDelete(@TempDir&"\fileget1.txt") RunWait(@ComSpec & " /c " & "dir H:\CIS-NG\*.* /b /OD >"&@TempDir&"\fileget1.txt",@TempDir,@SW_HIDE)_FileReadToArray(@TempDir&"\fileget1.txt",$FileGetList1) For $x = 1 to $FileGetList1[0] Local $hFile = FileOpen("H:\CIS-NG\"&$FileGetList1[$x], 2) If $hFile = -1 Then ContinueLoop Else FileClose("H:\CIS-NG\"&$FileGetList1[$x]) FileFlush("H:\CIS-NG\"&$FileGetList1[$x]) RunWait(@ComSpec & " /K " & "C:\Progra~2\7-zip\7z.exe t H:\CIS-NG\"&$FileGetList1[$x]&" -pPassword",@TempDir,@SW_MAXIMIZE) If @error Then FileDelete("H:\CIS-NG"&$FileGetList1[$x]) FileDelete("H:\Backups\7z.txt") FileWrite("H:\Backups\7z.txt","The readability of 7z, "&$FileGetList1[$x]&" has failed. The file has been deleted.") RunWait(@ComSpec & " /c " & "c:\backup\blat.exe H:\Backups\7z.txt -to backups@domain.com -server inet1.domain.com -subject "&'"'&"FAILED TEST OF 7z, "&$FileGetList1[$x]&" -f 7zTest@domain.com") Else FileMove("H:\CIS-NG"&$FileGetList1[$x],"H:\2BBURNED") FileDelete("H:\Backups\7z.txt") FileWrite("H:\Backups\7z.txt","The readability of 7z, "&$FileGetList1[$x]&" has passed.") RunWait(@ComSpec & " /c " & "c:\backup\blat.exe H:\Backups\7z.txt -to backups@domain.com -server inet1.domain.com -subject "&'"'&"PASSED TEST OF 7z, "&$FileGetList1[$x]&" -f 7zTest@domain.com") EndIf EndIf Next WEnd+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Paul Link to comment Share on other sites More sharing options...
water Posted May 16, 2012 Share Posted May 16, 2012 To make sure the file has successfully been transferred I would use a lock file:transfer the lock file xyz.lock (content doesn't matter)transfer the data file xyz.zipdelete the lock file xyz.lockAs long as xyz.lock exists you can't be sure that xyz.zip has been transferred successfully. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kylomas Posted May 16, 2012 Share Posted May 16, 2012 (edited) Paul, Two thiings: 1 - I don't see away out of your while...wend loop 2 - What is @error being set by in the following code?RunWait(@ComSpec & " /K " & "C:Progra~27-zip7z.exe t H:CIS-NG"&$FileGetList1[$x]&" -pPassword",@TempDir,@SW_MAXIMIZE) If @error Then Is it possible thast your pgm (7-zip) is opening a file and encountering an error? kylomas Edited May 16, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
OrthodoxyUSA Posted May 17, 2012 Author Share Posted May 17, 2012 To make sure the file has successfully been transferred I would use a lock file:transfer the lock file xyz.lock (content doesn't matter)transfer the data file xyz.zipdelete the lock file xyz.lockAs long as xyz.lock exists you can't be sure that xyz.zip has been transferred successfully. That's a good idea. It would work for my situation where I have control over both ends.Why wouldn't I just copy a text file at the end with the same name as the 7z and then hinge my job from that? My job could delete it when it's finished.Of course none of this would be an answer for someone who does not have control over the sending end.I was a bit shocked at not being able to find an easy answer for this inside AutoIt.I have a small program called Log Monitor 1.4.2 (© 1998-2002 Vadim Dumbravanu) that monitors a folder for changes, and performs an action when a file is closed. It works well for my purpose, but the product is no longer available and I think I could improve upon the idea for my purpose.Paul Link to comment Share on other sites More sharing options...
OrthodoxyUSA Posted May 17, 2012 Author Share Posted May 17, 2012 (edited) Paul, Two thiings: 1 - I don't see away out of your while...wend loop 2 - What is @error being set by in the following code?RunWait(@ComSpec & " /K " & "C:Progra~27-zip7z.exe t H:CIS-NG"&$FileGetList1[$x]&" -pPassword",@TempDir,@SW_MAXIMIZE) If @error Then Is it possible thast your pgm (7-zip) is opening a file and encountering an error? kylomas Hi kylomas, Answer to number one... it was intentional. Number two... I was hoping to pick up on the exit code of the 7z. (I've never tried before.) The only problem that the 7-zip is running into is that the file is still open. Thank for thinking about it! Paul Edited May 17, 2012 by OrthodoxyUSA Link to comment Share on other sites More sharing options...
water Posted May 17, 2012 Share Posted May 17, 2012 Why wouldn't I just copy a text file at the end with the same name as the 7z and then hinge my job from that? My job could delete it when it's finished.That's even easier and should work fine for your situation. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kylomas Posted May 17, 2012 Share Posted May 17, 2012 Paul, Using a file in a "handshaking" kind of technique will only work if you are certain that 7z always runs successfully. I would monitor the output to the command window for 7z messages as a basis for further actions (note: I've never used this program so the entire point may be moot). Command window output can be monitored with the stdout and stderr read functions. Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Blue_Drache Posted May 17, 2012 Share Posted May 17, 2012 7z is rather difficult to automate properly. I've yet to try the solutions put forward here: due to lack of time/will/Diablo 3 Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
OrthodoxyUSA Posted May 18, 2012 Author Share Posted May 18, 2012 Don't get hung up on the 7-zip's guys... that part works without problems.The problem is knowing when the incoming file is closed and no longer being written to, before we start testing the file.If we start the test before the file is finished OR something else has it open for any reason, the test will fail.Paul Link to comment Share on other sites More sharing options...
kylomas Posted May 18, 2012 Share Posted May 18, 2012 (edited) Paul,Precisely, so 7-z output needs to be monitored, yes?kylomasedit:additional infoHow will you know that the file is finished copying and free to be tested?see post #10 from the link provided by Blue_Drache Edited May 18, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jchd Posted May 18, 2012 Share Posted May 18, 2012 I'm not currently in the position to test anything but while the file is being written to, if you loop trying to open the file in append mode, it _should_ return an error. Again, untested. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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