{"id":106,"date":"2017-07-08T12:09:41","date_gmt":"2017-07-08T10:09:41","guid":{"rendered":"http:\/\/developer.ps\/?p=106"},"modified":"2026-09-22T20:52:17","modified_gmt":"2026-09-22T18:52:17","slug":"python-script-to-set-file-dates","status":"publish","type":"post","link":"https:\/\/developer.ps\/index.php\/2017\/07\/08\/python-script-to-set-file-dates\/","title":{"rendered":"Python Script to set file dates"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/python\r\n# -*- coding: utf-8 -*-\r\n\r\nimport sqlite3 as lite\r\nimport os, csv, sys, subprocess, hashlib, time\r\nfrom datetime import timedelta, datetime, tzinfo\r\nimport platform\r\n\r\ncon = lite.connect('files.db')\r\ncon.text_factory = str\r\nwith con:\r\n    for directory, subdirectories, filenames in os.walk('.'):\r\n        print(directory);\r\n        cur = con.cursor()    \r\n        cur.execute(\"SELECT * FROM data where path=:directory COLLATE NOCASE\", {\"directory\":directory})\r\n        con.commit()\r\n        row = cur.fetchone()\r\n        if row == None:\r\n            text_file = open(\"err_log.txt\", \"a\")\r\n            text_file.write(directory+\"\\n\")\r\n            text_file.close()\r\n        else:\r\n            #cts = float(abs(row[1]))\r\n            mts = float(\"0\" + abs(row[2])\r\n            if mts &lt; 0:\r\n                mts = float(\"0\" + abs(row[1])\r\n            os.utime(directory,(mts,mts))    \r\n            #print row[0], row[1], row[2]\r\n        for filename in filenames:\r\n            full_filename = os.path.join(directory, filename)\r\n            print full_filename;\r\n            cur.execute(\"SELECT * FROM data where path=:full_filename COLLATE NOCASE\", {\"full_filename\":full_filename})\r\n            con.commit()\r\n            row = cur.fetchone()\r\n            if row == None:\r\n                text_file = open(\"err_log.txt\", \"a\")\r\n                text_file.write(full_filename+\"\\n\")\r\n                text_file.close()\r\n            else:\r\n                #cts = float(abs(row[1]))\r\n                mts = float(\"0\" + abs(row[2])\r\n                if mts &lt; 0:\r\n                    mts = float(\"0\" + abs(row[1])\r\n                os.utime(full_filename,(mts,mts)) \r\n            \r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/python # -*- coding: utf-8 -*- import sqlite3 as lite import os, csv, sys, subprocess, hashlib, time from datetime import timedelta, datetime, tzinfo import platform [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":1,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":107,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/posts\/106\/revisions\/107"}],"wp:attachment":[{"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.ps\/index.php\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}