Delete Imported File After Successful Dataport Run

JohnieG
JohnieG Member Posts: 56
Hi to all,
I am trying to delete a file (which is also the dataport's file) after running an importing dataport and I am getting the following message: "You cannot use file c:\myfile.txt because it is already in use". I believe that this is because the code for deleting the file is placed on the PostDataport Trigger which is being executed while the imported file is still open. ](*,)
Is there any way that I can delete this file with code from inside the dataport? Am I doing something wrong or is this impossible?
Always Look On The Bright Side Of Life...

Answers

  • Mbad
    Mbad Member Posts: 344
    Did you try file.close?
  • Savatage
    Savatage Member Posts: 7,142
    edited 2007-01-08
    Text0001 ='Would You Like To Delete The File?'
    OnPostDataport
      BEGIN 
        CurrFile.CLOSE; 
             IF CONFIRM(Text0001,TRUE) THEN 
             ERASE(CurrDataport.FILENAME); 
      END;
    
  • JohnieG
    JohnieG Member Posts: 56
    It worked perfect.

    Thank you both for your quick and apposite remark! =D>

    I have much to learn...
    Always Look On The Bright Side Of Life...
  • Savatage
    Savatage Member Posts: 7,142
    You can easily Add more info like the # of Records Imported

    OrderCount = Variable Type Integer
    Text0001 = %1 Orders Imported / Would You Like To Delete The File?
    OnPreDataport()
    OrderCount := 0;   //initialize the count
    
    OnPostDataport()
    CurrFile.CLOSE;
    IF CONFIRM(Text0001,TRUE,OrderCount) THEN 
    ERASE(CurrDataport.FILENAME);
    
    OnAfterImportRecord()
    OrderCount := OrderCount + 1;  //counts # of records
    

    -Thanks to Mark Brummel for helping me with this many moons ago =D>
    http://www.mibuso.com/forum/viewtopic.php?t=8753