Sign in to follow this  
Followers 0
water

[SOLVED] When does a file "exist" ...

6 posts in this topic

#1 ·  Posted (edited)

Hi AutoIt Gurus,

I have the following problem:

An external program creates a PDF-file (~900KB) in a directory. My script checks for this file and when it exists it moves the file do another directory with a different name. Now I have a reproducible situation where I get an error from FileMove. When I wait a few seconds after I detect the file the script runs fine.

I think FileExists tells me "file found" even when the file is still being written by the other application. Therefore the error when moving the file.

What is the best way to tell that the file has been closed by the other application?

Thanks for your help in advance!

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites



Hi AutoIt Gurus,

I have the following problem:

An external program creates a PDF-file (~900KB) in a directory. My script checks for this file and when it exists it moves the file do another directory with a different name. Now I have a reproducible situation where I get an error from FileMove. When I wait a few seconds after I detect the file the script runs fine.

I think FileExists tells me "file found" even when the file is still being written by the other application. Therefore the error when moving the file.

What is the best way to tell that the file has been closed by the other application?

Thanks for your help in advance!

You can't move a file that is in use (open) by another program. If you know the size of the file then you wight want to check with FileGetSize() instead of FileExists(). Or if the external program closes after creating the file then use ProcessExists() to see if it's moveable yet or not. There are several methods of checking for what you need.

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!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for your reply!

Unfortunately I don't know the size of the file. It was just an example and the size varies.

The external program is running on another machine (a server that converts print files to pdf) so I can't check the process.

I was thinking of some code to check wether someone else has the file open for reading or writing.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Not 100% sure, but try FileOpen("Name", 1). I believe it will fail if the file is still being written to.

Share this post


Link to post
Share on other sites

You could check for the modification date/time that its at least xx seconds old so you can safely assume the writing is done ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks a lot for your replies!

I'll try the FileOpen approach.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0