windows - How to check a file saving is complete using Python? -


I'm trying to automate a downloading process. In this, I want to know whether the savings of a particular file have been completed or not. The scenario is such.

  1. Chrome or Firefox (Open Any site using the browser)
  2. page Save to disk using 'Kretl + S' on Windows)
  3. Now if the page is too big, it takes seconds to save it. After the save is complete I want to parse the html.

I do not have the control to save the browser functionality, so I do not know if the save process is complete or not.

One idea I thought, keep a little to get the md5sum of the file using the long loop, and check against previous calculations, and matches past and current md5 sum up the loop continues Is for. It works, I think, as this browser first tries to save a file in a TMP file and then copies the content to the specified file (or just renames the file).

Any thoughts? I use the python for automation, so any idea which can be implemented using Python is welcome.

thank you induced

On Windows you try to open the file in exclusive usage mode So that it can be ascertained whether it is used (read or written) by any other program. I have to wait for the side full FTP upload server is used, here's the code:

  def check_file_ready (Self, Path): check '' that file by another process Not opened. 'Handle = no try: handle = win32file.CreateFile (path, win32file.GENERIC_WRITE, 0, no, win32file.OPEN_EXISTING, win32file.FILE_ATTRIBUTE_NORMAL, no) to return except pywintypes.error True, E: If e [0] == winerror.ERROR_SHARING_VIOLATION: # Note: other possible error code # winerror.ERROR_FILE_NOT_FOUND # winerror.ERROR_PATH_NOT_FOUND # winerror.ERROR_ACCESS_DENIED. After taking wrong: If the handle: win32file.CloseHandle (handle)  

Note: This function makes sharing all Win32 errors despite sharing again. You should check the file for existence first or check the additional error code in the function (see comment on line 15).


Comments