How to detect whether a file has been modified

cunnycunny Member Posts: 129
edited 2008-09-23 in NAV Tips & Tricks
Hey guys,

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.

Regards,
cunny Lee
MCP - MBS Navision
jle@naviworld.com

Comments

  • garakgarak Member Posts: 3,263
    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.

    To check DateLastModified u can use WSH -> File.

    Regards
    Do you make it right, it works too!
  • cunnycunny Member Posts: 129
    Hi garak,

    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,
    cunny Lee
    MCP - MBS Navision
    jle@naviworld.com
  • garakgarak Member Posts: 3,263
    An example:
    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.

    Regards
    Do you make it right, it works too!
  • krikikriki Member, Moderator Posts: 9,094
    [Topic moved from Navision forum to Navision Tips & Tricks forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • cunnycunny Member Posts: 129
    Hi garak,

    Perfect! Thank you very much =D> !

    Regards,
    cunny Lee
    MCP - MBS Navision
    jle@naviworld.com
  • garakgarak Member Posts: 3,263
    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)

    Regards
    Do you make it right, it works too!
  • cunnycunny Member Posts: 129
    Hi garak,

    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,
    cunny Lee
    MCP - MBS Navision
    jle@naviworld.com
Sign In or Register to comment.