just came up with a question, how to detect whether file has been modified after I open it and close it. I tried to use GETSTAMP but did not get it through.
when you open the file you can check the property DateLastModified, if this property is changed (OldDateLastModified <> ActualDateLastModified) before you close it, an other programm has modified it.
Name DataType Subtype Length
WSHFSO Automation 'Windows Script Host Object Model'.FileSystemObject
WSHFile Automation 'Windows Script Host Object Model'.File
OldDate Date
NewDate Date
OldFileSize Integer
NewFileSize Integer
....
//here you open the file
....
if isclear(WSHFSO) then
create(WSHFSO);
if WSHFSO.FileExists(ThePathAndTheFile) then begin
WSHFile := WSHFSO.GetFile(ThePathAndTheFile);
OldDate := WSHFile.DateLastModified();
OldSize := WSHFile.Size;
end;
.....
//here you read the file or what else in you C/AL is
.....
//now you will check if the file is changed during your reading
if WSHFSO.FileExists(ThePathAndTheFile) then begin
WSHFile := WSHFSO.GetFile(ThePathAndTheFile);
NewDate := WSHFile.DateLastModified();
NewSize := WSHFile.Size;
end;
clear(WSHFSO);
if (OldDate <> NewDate) or (OldSize <> NewSize) then
message('Somebody has change the file');
On the other hand, if you read the file with a File variable, and set before the property Writemode before you open it, no other program can change the file.
You're welcome,
so could you set the Attribute in your first post to Attribute: [Solved] (go to first post -> Button Edit -> Drop down Field in the header)
One more thing, the code works great but does not suit my requirement very well. What I want to do is when I open a file let's say a text and give some change, then I close it, at this moment, I need to check whether the text file has been modified or not. If yes I will have to tell the user about it and provide a function to replace the old one with the newest file. I have checked WSH to find some similar function but failed. Any idea?
Comments
To check DateLastModified u can use WSH -> File.
Regards
Thanks very much. But I could not find such a function you mentioned, could you tell me a little more about it? By the way, what is WSH :-k
Regards,
MCP - MBS Navision
jle@naviworld.com
On the other hand, if you read the file with a File variable, and set before the property Writemode before you open it, no other program can change the file.
Regards
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Perfect! Thank you very much =D> !
Regards,
MCP - MBS Navision
jle@naviworld.com
so could you set the Attribute in your first post to Attribute: [Solved] (go to first post -> Button Edit -> Drop down Field in the header)
Regards
One more thing, the code works great but does not suit my requirement very well. What I want to do is when I open a file let's say a text and give some change, then I close it, at this moment, I need to check whether the text file has been modified or not. If yes I will have to tell the user about it and provide a function to replace the old one with the newest file. I have checked WSH to find some similar function but failed. Any idea?
Best Regards,
MCP - MBS Navision
jle@naviworld.com