Dataports - deleting source file

I am attempting to automate a Dataport to 1. Look for the file it needs with EXISTS function 2. Delete the file once it is done with the file with ERASE function The file is hard-coded into the Dataport. I put the statement to look for the file in the OnInitDataPort event I put the statement to ERASE the file in the OnPostDataPort event Two things happen: When the dataport opens it bombs and says it cant find the file, rather than the soft landing I am attempting to do by checking for the existence of the file and exiting if it can’t find it. Then it says it can’t ERASE the file because it is in use. Is it possible to make the Dataport do these things, or am I barking up the wrong tree Devin W. McMahon, MCDBA

Hi Devin, To use your own words: you are barking up the wrong tree . The only way to do what you are doing is by having another object call the dataport and do the checking and the deleting of the file. The reason you cannot delete the file is because the dataport has a lock on it until it finishes so therefore there is no way to delete while still in the dataport. Also it is never a nice thing to harcode … You should have a setup for the file name … SO good luck. Cristi

You could try this:

OnPreDataport()
IF NOT EXISTS(CurrDataport.FILENAME) THEN
  CurrDataport.QUIT;

and

OnPostDataport()
VarFileName := CurrFile.NAME;
CurrFile.CLOSE;
YIELD; // To make the OS realy close the file
ERASE(VarFileName);

Maybe that helps … Regards, Jörg Joerg A. Stryk Apollo-Optik, IT/ERP

There is another one way to force file deleting within DATAPORT in OnPostDataport section insert something like this: SHELL(‘command.com’, ‘/c’, 'del ’ + filepath); Looks not so petty but works…