title: How to detect if a file has been renamed?
body: <p>I am currently implementing <strong>my own version of WatchService API</strong> in <em>Java</em>. </p>
  
  <p>(You can refer to this <a href="https://dzone.com/articles/how-watch-file-system-changes" rel="nofollow noreferrer">example</a>  to understand what file <em>WatchService</em> does.) </p>
  
  <p>I have <strong>implemented code for</strong> the following cases : </p>
  
  <ul>
  <li>Whenever a <strong>file has been created</strong> inside the directory or its sub-directory.</li>
  <li>Whenever a <strong>file has been deleted</strong> from the directory or its sub-directory.</li>
  <li>Whenever a <strong>file has been modified</strong> inside the directory or its sub-directory. <em>(based on the comparison of the last-modified date of files)</em></li>
  </ul>
  
  <p>I am facing a problem, whenever a file has been renamed, I don't understand how to track it.</p>
  
  <p>This link contains the gist of my code at high level: <a href="https://paste2.org/wMAnIbkA" rel="nofollow noreferrer">click here</a>  </p>
  
  <p>Whenever a file has been renamed, I get 2 results</p>
  
  <blockquote>
    <p><strong>FILE DELETED :</strong> <em>{old filename}</em><br>
    <strong>FILE ADDED :</strong> <em>{new filename}</em></p>
  </blockquote>
  
  <p>But what I want the actual result to be is :</p>
  
  <blockquote>
    <p><strong>FILE RENAMED:</strong> FROM <em>{old filename}</em> TO <em>{new filename}</em></p>
  </blockquote>
  
  <p>How do I tackle this challenge ?</p>
  
  <p>I have provided a psuedo-code (which I think is enough to understand the problem at hand), If required I can provide the whole code too :)</p>