{"id":532,"date":"2007-05-29T18:06:30","date_gmt":"2007-05-30T01:06:30","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/2007\/05\/29\/how-to-update-file-timestamps-in-python\/"},"modified":"2007-05-29T18:06:30","modified_gmt":"2007-05-30T01:06:30","slug":"how-to-update-file-timestamps-in-python","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/how-to-update-file-timestamps-in-python\/","title":{"rendered":"How to update file timestamps in Python"},"content":{"rendered":"<p>Sometimes you can be real picky like me about timestamps of files, for example, during my wedding we had a few digital cameras, and one of the cameras had its internal clock 4 hours behind. So what better way for a lazy guy like you to change timestamps than writing a short python script to fix the problem.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/farm1.static.flickr.com\/199\/510507306_179804ba0b.jpg?w=640\"\/><\/p>\n<p>I wrote this script on the same folder where the pictures with the lagged modification times existed:<\/p>\n<pre>\nimport os\nimport time\nfrom stat import *\n\n#returns a list of all the files on the current directory\nfiles = os.listdir('.')\n\nfor f in files:\n  #my folder has some jpegs and raw images\n  if f.lower().endswith('jpg') or f.lower().endswith('crw'):\n    st = os.stat(f)\n    atime = st[ST_ATIME] #access time\n    mtime = st[ST_MTIME] #modification time\n\n    new_mtime = mtime + (4*3600) #new modification time\n\n    #modify the file timestamp\n    os.utime(f,(atime,new_mtime))\n<\/pre>\n<p>Very nice, I like<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you can be real picky like me about timestamps of files, for example, during my wedding we had a few digital cameras, and one of the cameras had its internal clock 4 hours behind. So what better way for a lazy guy like you to change timestamps than writing a short python script to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,30,43,65],"tags":[],"class_list":["post-532","post","type-post","status-publish","format-standard","hentry","category-code","category-geeklife","category-linux","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-8A","jetpack-related-posts":[{"id":2749,"url":"https:\/\/www.gubatron.com\/blog\/deploying-html5-apps-on-cloudfront-with-efficient-invalidation-requests\/","url_meta":{"origin":532,"position":0},"title":"Deploying HTML5 apps on CloudFront with efficient invalidation requests","author":"gubatron","date":"June 8, 2012","format":false,"excerpt":"So you decided to build your next web app\/site using nothing but HTML5 and Javascript. No server side processing for anything related to UI. This means you will be coding a lot of JavaScript. Wouldn't it be nice to put all that static HTML and JS on your CloudFront CDN\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":572,"url":"https:\/\/www.gubatron.com\/blog\/list-dir-by-gubatron-list-your-directories-on-a-text-file-with-a-right-click\/","url_meta":{"origin":532,"position":1},"title":"List Dir by Gubatron &#8211; List your directories on a text file with a right click","author":"gubatron","date":"August 12, 2007","format":false,"excerpt":"Last week my wife told me if I knew an easy way (without using the cmd.exe) on Windows to list the contents of a directory, she basically wanted to give her users a one click solution to list the contents of a folder and have them on notepad. So, I\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":516,"url":"https:\/\/www.gubatron.com\/blog\/ejemplo-de-automatizacion-entre-2-maquinas-remotas-con-bash-scripting-y-python\/","url_meta":{"origin":532,"position":2},"title":"Ejemplo de automatizacion entre 2 maquinas remotas con bash scripting y Python","author":"gubatron","date":"May 10, 2007","format":false,"excerpt":"Para los amigos que se inician en el mundo *nix, ya sea con su nueva Mac, o con una PC corriendo Linux, les recomiendo que aprendan a manejar bien los siguientes lenguajes, y el mundo sera suyo: - bash scripting (aliases, variables, exports, iteraciones, condicionales) - python (para programar logica\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1015,"url":"https:\/\/www.gubatron.com\/blog\/python-script-to-update-wordpress-in-one-step\/","url_meta":{"origin":532,"position":3},"title":"Python Script to Update WordPress in One Step","author":"gubatron","date":"November 26, 2008","format":false,"excerpt":"During the past week, I think I had to update all my wordpress instances twice, and it's become really annoying doing this manually. I've written a python script which I'll share with you. How I keep my wordpress updated by hand I tend to keep my wp-content folder outside of\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":470,"url":"https:\/\/www.gubatron.com\/blog\/how-to-build-pyqt4-for-windows\/","url_meta":{"origin":532,"position":4},"title":"How to build PyQt4 for Windows","author":"gubatron","date":"February 23, 2007","format":false,"excerpt":"- Make sure you don't have cygwin or C:devkitPromsysbin in your path, or else your make files can end up trying to run the Makefile using 'sh' and all the makefile we're about to use are meant to run from the windows command line. If for some odd reason you\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3195,"url":"https:\/\/www.gubatron.com\/blog\/how-to-import-a-backed-up-wallet-in-bitcoin-qt\/","url_meta":{"origin":532,"position":5},"title":"How to import a backed up wallet in Bitcoin-Qt","author":"gubatron","date":"November 20, 2013","format":false,"excerpt":"The Bitcoin-Qt client has an export feature, but not an import feature, importing a wallet is a bit of a manual process and it can be quite scary for the non-computer saavy since you need to do this kind of stuff because you got a new computer or your old\u2026","rel":"","context":"In &quot;BitCoin&quot;","block_context":{"text":"BitCoin","link":"https:\/\/www.gubatron.com\/blog\/category\/bitcoin-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}