Erasing a file with full path - slash problems

andy76andy76 Member Posts: 616
Hello,

I have to delete a file in a full path position, for example,

'C:\Documents and Settings\pippo\Documenti\WindowsCE My DocumentsReadings.txt'

I have the error Syntax error and the file is not deleted.

Trying to make a message with 'C:\Documents and Settings\pippo\Documenti\WindowsCE My DocumentsReadings.txt' I see that slash are considered as line feeds. I don't know if this is the real problem but I ask you how the syntax of the full path should be.

Thank you

Comments

  • SavatageSavatage Member Posts: 7,142
    are your trying to delete or make a message? or both? where are you deleting this from?
  • andy76andy76 Member Posts: 616
    This is the code:


    Dataport - OnPostDataport()
    MESSAGE('C:\Documents and Settings\pippo\Documenti\WindowsCE My Documents\Readings.txt');
    IF ERASE('C:\Documents and Settings\pippo\Documenti\WindowsCE My DocumentsReadings.txt') THEN
    MESSAGE('Pesature importate e file cancellato')
    ELSE BEGIN
    MESSAGE('Errore nella cancellazione del file: ' + GETLASTERRORTEXT);
    CLEARLASTERROR;
    END

    ---
    I have syntax error also writing

    IF ERASE(CurrDataport.FILENAME) THEN
    MESSAGE('OK')
    ELSE BEGIN
    MESSAGE('Error: ' + GETLASTERRORTEXT);
    CLEARLASTERROR;
    END


    Thank you
  • SavatageSavatage Member Posts: 7,142
    if filename & message are always a contant then make it a text constant and use
    message('%1',MyTextConstant);

    see pic
  • andy76andy76 Member Posts: 616
    I tried again but I have the error blank without any description

    ERASE = false and GETLASTERROR = '' blank...What is the problem? Navision can not delete the folder of Active Sync syncronized with the PDA?

    Thank you
  • andy76andy76 Member Posts: 616
    With your advice to use a text constant the file is deleted correctly...
    but I would like to read the path from a variable field...Isn't it possible?
  • garakgarak Member Posts: 3,263
    MyVar := 'C:\\Dokumente und Einstellungen\\Rene\\Desktop\\neu.txt';
    erase(MyVar);
    Do you make it right, it works too!
  • SavatageSavatage Member Posts: 7,142
    andy76 wrote:
    I have syntax error also writing

    IF ERASE(CurrDataport.FILENAME) THEN
    MESSAGE('OK')
    ELSE BEGIN
    MESSAGE('Error: ' + GETLASTERRORTEXT);
    CLEARLASTERROR;
    END

    I doubt it will ever not be OK unless something wierd is happening.
    in regards to syntax - you should always post your error message - it helps alot
    looks like you're doing an else begin without a then begin
    IF ERASE(CurrDataport.FILENAME)
     THEN BEGIN
       MESSAGE('OK');
    END
     ELSE BEGIN
       MESSAGE('Error: ' + GETLASTERRORTEXT);
       CLEARLASTERROR;
    END;
    

    Does it work without a close????
    CurrFile.CLOSE;


    Personally I like to use a confirm message
    OnPostDataport()
    CurrFile.CLOSE;
    IF CONFIRM('Would You Like To Delete The File,TRUE) THEN BEGIN
    SavedFileName := FORMAT(WORKDATE,0,'<Year4>'+'-'+'<Month Text,3>'+'-'+'<Day,2>')+'.txt';
    FILE.COPY(CurrDataport.FILENAME,FilePath+SavedFileName);
    ERASE(CurrDataport.FILENAME);
    END;
    

    What mine does is delete the orig file from it's orig location but saves a copy in another folder called 'Completed Imports' using the date as it's new name.
    filepath= I:\Internet Data Feed\Completed Import\

    each person does it there own way (here's the same code without the bells n' whistles)
    OnPostDataport()
    CurrFile.CLOSE;
    IF CONFIRM('Would You Like To Delete The File,TRUE)
     THEN BEGIN
      ERASE(CurrDataport.FILENAME);
    END
     ELSE BEGIN
      MESSAGE('File %1 not deleted',CurrDataport.FILENAME);
    END;
    
  • andy76andy76 Member Posts: 616
    solved, thank you very much Savatage.
  • andy76andy76 Member Posts: 616
    Hello everyone,

    I return on a my previous post that was solved more than 3 years ago.

    Now I have again the problem on another development/customer.
    I pass all the full path + file name to function ERASE but FILE.ERASE return false and don't delete the file.

    I cannot insert the entire name of the file in a text constant because:
    - the full path is a setup table so can be changed and edited
    - the name of the file is variable because the file in the directory have name that continues to change (with a progressive number).

    So I ask you how I can solve this in a clever way.

    Thank you
  • andy76andy76 Member Posts: 616
    The file must be closed? Or is it closed automatically?
    In NAV 5.0 sp1 there is not FILE.CLOSE function?

    Thank you
Sign In or Register to comment.