title: Hdfs file or folder created or modified date using python
body: <p>To find number of days a file or folder is created for in hdfs, I used following python code.</p>
  
  <pre><code>import datetime
  from datetime import datetime
  
  def get_days(directory, file)
  
      current_datetime = datetime.now()
      command = "hadoop fs -ls " + directory + file + " | tr -s ' ' | cut -d' ' -f6-7 | grep '^[0-9]' "
      status, output = shell_command(command)
          if status == 0:
              file_date = datetime.strptime(output, '%Y-%m-%d %H:%M')
              date_period = current_datetime - file_date
      return date_period.days
  </code></pre>
  
  <p>It threw following error</p>
  
  <pre><code>File "/usr/lib64/python2.7/_strptime.py", line 325, in _strptime (data_string, format)) 
  ValueError: time data 'log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.UserGroupInformation).\nlog4j:WARN Please initialize the log4j system properly.\nlog4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.\n2018-04-11 14:08' does not match format '%Y-%m-%d %H:%M'
  </code></pre>
  
  <p>The only reason I can think of is that the output is a variable of inferred type Unicode. Is there any other way to find the modified date or age of a Hdfs file in python? please advise. Any changes to the above code are also welcome. Thanks in advance. </p>