Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change file creation date on Windows with PHP

Tags:

php

windows

In php I can change the file last modification and access time arbitrarily with touch()

<?php
touch($filename,mktime(0,0,0,2010,1,10));

...but how to change the creation time?

Why do I need this? Well, If I retrodate a file or a directory mtime to before their creation date, explorer.exe keeps showing me the more recent creation date instead.

like image 470
ZJR Avatar asked Jun 21 '12 23:06

ZJR


1 Answers

Mh, an unsatisfactory, but working, approach I found out about, is: using nircmd.
Nircmd is a 37kb utility. (redistributable, closed-source, freeware)

How to proceed:

<?php

$time=strftime('%d-%m-%Y %H:%M:%S',$time);
$cmd=".\\nircmdc.exe setfilefoldertime \"$filename\" \"$time\"";
system($cmd);

Notes:

  • nircmdc.exe is the command line version of nircmd (note the additional c before .exe)
  • setfilefoldertime is a nircmd sub-command, it is documented here.

Still, I hope there is a COM or WMIC solution I couldn't find this time around.

like image 153
ZJR Avatar answered Oct 13 '22 06:10

ZJR