I am trying to move a file between directories on the same filesystem. The difficulty I am having is that when I use rename() the file access time is changed for that file on the filesystem.
I tried using shell_exec() with mv, though for some reason when I call mv in this way it copies the file and then deletes the original which takes much longer.
Is there any way to move the file quickly without changing the access time? Or can I change it back after calling rename()?
As a general rule the access time from a file must be changed when a function like
rename(), or any other function that access a file, do it.As for changing the access time of a file. This is only possible using the touch function, like described in the manual:
As you can see the time parameter is described in the manual as:
And here is an example from the same page of setting the access time one hour back from a file:
However, be aware that the touch function, as described, attempts to change the file. If you have no permission for example the function will return
false. (and won’t change the file time)Cheers