Jump to content
Macro Express Forums

Wait for File to Exist


Recommended Posts

Hi Guys,

 

I've been running into an issue with a couple of lines of script.

 

I've tried two different ways of doing this and my macro keeps stalling at this step every other time I run it. I will run the macro once and it will work, then it will stall the 2nd time through, then work the third. It's really boggling.

 

The entire script repeats on a loop determined by a variable at the beginning of the script. It copies a Lotus Notes ID file from an attachment in an Outlook email to a network drive that the script previously mapped, this is where it stalls.

The script succeeds in saving the .ID file to the network drive every time. Afterwards, it i supposed to wait for the file to exist on the network drive and then proceed. The problem is that it's not proceeding. I have to manually cancel the macro, and the next time I run it, it works fine. I have even deleted the .ID file from the network drive as a troubleshooting step to basically "reset" the script to run as if it hadn't done anything yet. I wanted to see if it just wasn't refreshing the network drive to look for the file, but the script still functions fine when I run it again.

 

I know the problem happens in this section of the script because I have the dialogue box set to tell me what line it was canceled on (as a side note, it is quite annoying that the "Don't show this again" box is ticked by default, making it so that I have to untick it every time).

 

Anyway, I've tried the simple "Wait For File To Exist" command:

<WAIT FOR FILE TO EXIST Filename="%Path[1]%" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<COPY FILE/FILES Source="%Path[1]%" Dest="%Path[2]%" Progress="TRUE" Recurse="FALSE"/>

and the slightly more complicated "infinite loop until file exists" script:

<REPEAT UNTIL Variable="%T[1]%" Condition="\x01" Value="%T[1]%"/>
<DELAY Flags="\x02" Time="500"/>
<IF FILE EXISTS File="%Path[1]%" Search_Path="FALSE"/>
<REPEAT EXIT/>
<END IF/>
<END REPEAT/>
<COPY FILE/FILES Source="%Path[1]%" Dest="%Path[2]%" Progress="TRUE" Recurse="FALSE"/>

 

In an earlier version of this script I was merely using Z:\%ID%.ID as the path, where %ID% was the filename (I had to add the extension .ID to it because they weren't saving as ID files) but it wasn't saving at all until I started setting the entire path and file name to the variable %Path[1]%. I guess it didn't like embedded variables or something. Anyway, in both scripts above, I can see that the file exists, yet the script will not proceed beyond this point. It is copying the filename directly from the file and saving it to a variable before it saves it to the Z: drive, so it's not an issue of syntax or spaces in the name (and if it were, it shouldn't work the 2nd time I run the script either).

 

Anyone have any ideas as to a fix or the root issue?

Link to comment
Share on other sites

You might try "Wait for file ready" instead of "Wait for File Exist". Often it takes time for an app to populate the file and the macro can act too quickly on a file that has no data yet. Also what if you create a test macro that create the file. Does that have the same problem?

Link to comment
Share on other sites

I would think that MacEx would be moving on from that step if it acted too quickly on the file though. It was getting hung up on the "Wait for file to exist" step, not the "copy file from one path to another" step. Regardless, I did try the "Wait for file to be ready" command anyway, and got the same results.

 

I don't actually create the file, I only save it from an email attachment in Outlook to the network drive. It often does take awhile to save it from Outlook, because the network drive is based out of Europe.

 

Hah, when I was creating the test script as you suggested, I just found the error. %ID[1]% was supposed to be %ID[%N[1]%]% in the below line:

<VARIABLE SET STRING Option="\x00" Destination="%Path[1]%" Value="Z:\\%ID[1]%.ID" NoEmbeddedVars="FALSE"/>

So it was looking for the first ID file every time, rather than the current ID file. The issue makes complete sense now. Thanks for the assist. :)

Link to comment
Share on other sites

Too bad I didn't have time to try your code so I couldn't have seen that.

 

Suggestion. If you create a simplified demonstration macro it helps users like my review and comment on your problem. That's a good reason but an unexpected reason is that you will often find the problem yourself! Several times I've created a simple macro to demonstrate some problem with MEP only to find my sample macro worked. First of all it helps one understand that what we suspect is the problem is not the actual problem and it allows one to compare the differences between the simple demonstration macro and your real code. It's saved me many embarrassing posts for some stupid mistake of my own.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...