简体   繁体   中英

Change file creation date on Windows with PHP

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.

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.

Try this one you can change file creation time and modify time

Win32 Console ToolBox 1.1

exec('touch.exe /c /t "file.html" '. date('H:i:s'));

nircmdc -> is to powerful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM