// Clear and reset list of import files: CLEAR(FileList); FileList.RESET; FileList.SETCURRENTKEY(Path); FileList.SETRANGE(Path, ''); FileList.SETRANGE("Is a file", TRUE); IF FileList.FIND('-') THEN ; // Open and read Excel files: FileList.RESET; FileList.SETCURRENTKEY(Path); FileList.SETRANGE(Path, ImportFromDirectory); FileList.SETRANGE("Is a file", TRUE); IF FileList.FIND('-') THEN BEGIN REPEAT // Copy import file from Import From Directory (remote computer) into Archive Directory (local computer) // erase import file from Import From Directory (remote computer) // and then safely read import file form Archive directory (local computer): IF [b]FILE.COPY[/b](ImportFromDirectory+'\'+FileList.Name, ArchiveDirectory+'\'+FileList.Name) THEN BEGIN // here is problem IF NOT FILE.ERASE(ImportFromDirectory+'\'+FileList.Name) THEN LogFileGlob.WRITE(FORMAT(TIME, 0, '<Standard Format,0>') + ';' + 'err' + ';' + ImportFromDirectory+ '\'+FileList.Name + ';' + '0;' + 'Could not erase file ' + ImportFromDirectory+ '\'+FileList.Name + ';') ELSE IF FORSDataImport(ArchiveDirectory+'\'+FileList.Name) THEN CurrForm.UPDATE(FALSE); END ELSE LogFileGlob.WRITE(FORMAT(TIME, 0, '<Standard Format,0>') + ';' + 'err' + ';' + ImportFromDirectory+ '\'+FileList.Name + ';' + '0;' + 'Could not move file ' + ImportFromDirectory+ '\'+FileList.Name + ' to archive directory;'); UNTIL FileList.NEXT = 0; END;
Comments
Try to do ChangeDatetime on the file. The function is SETSTAMP.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Thanks, ara3n.
Seems to me your solution is better =D>
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Previous solution failed - because customer changed requirement ](*,) ](*,) ](*,)
Now the file which I need to read will always have read only access. It mean that previous solution would not work - SETSTAMP will always return false.
So, how can Navision understand is the file not busy by other program if I can not use SETSTAMP or RENAME?
Any help will be appreciated!
Thanks in advance!
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Copy also not useful because if file is busy, copy will create file with size=0 and hold access until Navision restart. In my task import must work 24\7 without any control from users.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I have created such simple code in test codeunit:
Where WSH is Windows Script Host.
It works! It works when file not used by any programs and it works if file opened in Excel.
Thanks, ara3n!
But, in my case file can be opened programmatically in Excel by third party program for exporting data from this third party program. So Navision can open this file in the moment when file is still writing... How to define file opened for writing and still is writing or file opened only for reading? Guess, this issue I should discuss with my customer...