Help with txt files...

FranklinFranklin Member Posts: 253
Good morning,

I'm having problems with a txt file and do not understand the cause.

What I do is, once imported a file with a dataport, take it to a history folder and then clear the txt.

To take it a history folder I do the following:

vRutaConfiguracion: = 'C: \ test \ production \ entries';
vRutaOrigen: vRutaConfiguracion + = '\ file.txt';
vRutaDestino: vRutaNueva + = '\ file.txt;
File.Copy (vRutaOrigen, vRutaDestino)

Then I write:

OutFile.CREATE (vRutaOrigen)

(It is assumed that re-create that file, I overwrite the previous one and will remain empty)

But NAV sohows me this error:

"You can not access the file C: \ test \ production \ inputs \ file.txt"

That's just the path and I have to create file and folder permissions issues of windows is not.

Comments

  • krikikriki Member, Moderator Posts: 9,110
    you may not have blanks in the subdir if there aren't in reality.
    I think you need this: 'C:\test\production\entries'.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • pduckpduck Member Posts: 147
    Try the same thing with a slash instead of backslash. Does it work now?
  • matttraxmatttrax Member Posts: 2,309
    Also, if you are doing it inside the dataport, I believe it maintains a lock on the file until it's done. So you can't overwrite / change it.
  • FDickschatFDickschat Member Posts: 380
    Which line of your code creates the error? It could already be the copy if you have programmed this inside the dataport. Try to move the code which copies and clears the file into a codeunit which first calls the dataport and then copies and clears the file - which creates another problem, because the other software which writes into this file could already have written into the file inbetween.

    If another software writes to the file and assumes it does exist at all times I would not process the file directly then delete and recreate it (which might place a lock on the file for several seconds) but I would first rename the file and immediately create an empty file at the same place. Then you can do your processing on the renamed file while the other process can still write to "his" file.
    Frank Dickschat
    FD Consulting
  • SavatageSavatage Member Posts: 7,142
    What we do is on after we import a file. I ask if you want to delete the file & if yes then It moves the completed file to a "History" folder and deletes the orginal file from the "Working" folder.

    Text Constants:
    FilePath -> I:\Data Feed\History\
    Text0001 -> %1 Orders Imported / Would You Like To Delete The File?

    OnAfterImportRecord()
    OrderCount := OrderCount + 1;

    OnPostDataport()
    CurrFile.CLOSE; //Close the text file once done
    IF CONFIRM(Text0001,TRUE,OrderCount) THEN BEGIN //ask what the next step should be
    SavedFileName := FORMAT(WORKDATE,0,'<Year4>'+'-'+'<Month Text,3>'+'-'+'<Day,2>'+'-'+DELCHR((FORMAT(TIME)),'=',':'))+'.txt'; //create a History filename with date & time stamp.
    FILE.COPY(CurrDataport.FILENAME,FilePath+SavedFileName); //Copy the orig file to the History directory
    ERASE(CurrDataport.FILENAME); //erase the orig file
    END;
Sign In or Register to comment.