<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vikram</title>
    <description>The latest articles on DEV Community by Vikram (@vikramnr).</description>
    <link>https://dev.to/vikramnr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F270065%2F598ad5b3-bda3-423c-a1c8-54e63c172360.jpeg</url>
      <title>DEV Community: Vikram</title>
      <link>https://dev.to/vikramnr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vikramnr"/>
    <language>en</language>
    <item>
      <title>Housekeeping files using python modules </title>
      <dc:creator>Vikram</dc:creator>
      <pubDate>Sun, 04 Jul 2021 11:38:43 +0000</pubDate>
      <link>https://dev.to/vikramnr/housekeeping-files-using-python-modules-33io</link>
      <guid>https://dev.to/vikramnr/housekeeping-files-using-python-modules-33io</guid>
      <description>&lt;p&gt;File module in python has a lot of useful properties. It provides access to various file properties related to time which then can be plugged in use cases like housekeeping, archiving or building logic based the file modified or created time.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;os.path.getatime()&lt;/code&gt; returns the access time, &lt;/p&gt;

&lt;p&gt;&lt;code&gt;os.path.getmtime()&lt;/code&gt; returns the modification time and &lt;/p&gt;

&lt;p&gt;&lt;code&gt;os.path.getctime()&lt;/code&gt; returns the creation time&lt;/p&gt;

&lt;p&gt;&lt;code&gt;os.path.getsize()&lt;/code&gt; returns the amount of data in the file, represented in bytes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ospath_properties.py
import os.path
import time

print('File         :', __file__)
print('Access time  :', time.ctime(os.path.getatime(__file__)))
print('Modified time:', time.ctime(os.path.getmtime(__file__)))
print('Change time  :', time.ctime(os.path.getctime(__file__)))
print('Size         :', os.path.getsize(__file__))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 ospath_properties.py

File         : ospath_properties.py
Access time  : Sun Mar 18 16:21:22 2018
Modified time: Fri Nov 11 17:18:44 2016
Change time  : Fri Nov 11 17:18:44 2016
Size         : 481
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A simple script to archive files from given directory using getctime&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# housekeep_files.py

import os
import time
from datetime import datetime

# get list of file names
file_names = os.listdir()
archive_days = 90
now = datetime.now()

for file in file_names:
   # get created time of file and convert to datetime
   created_time = time.ctime(os.path.getctime(files[0]))
   created_datetime = datetime.strptime(c_time, "%a %b %d %H:%M:%S %Y")
   diff_days = (now - created_datetime).days

   # find difference between archive and current day
   if days &amp;gt; archive_days:
      # logic here to copy or move or remove files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
