MATLAB: Changing the timestamp of files from MATLAB

MATLAB

I want to change the timestamp of multiple files using MATLAB. Is there a way to do so?

Best Answer

You can shell out and use PowerShell (or something similar depending on the OS) to do this.
For MATLAB, please consider the following workflow to change the time metadata for files on Windows (as an example):
1. Create an empty file. In this example, let it be 'temp.m'.
2. Open MATLAB and change to the directory where the file exists.
3. In the MATLAB Command Window, enter the following lines of code to change the different 'time' metadata values for the files:
>> !powershell $(Get-Item temp.m).lastwritetime=$(Get-Date \"11/24/2015 05:00 am\")
>> !powershell $(Get-Item temp.m).creationtime=$(Get-Date \"11/24/2015 05:00 am\")
>> !powershell $(Get-Item temp.m).lastaccesstime=$(Get-Date \"11/24/2015 05:00 am\")
The explanation for these command is as follows:
The '!' command lets you execute operating system commands from the Command Window of MATLAB. For more information, refer to the following link
The 'powershell' keyword executes the line following it in the Windows PowerShell
You need to use double quotes with a backslash (\") to let the system know that this part of the command since MATLAB uses double quotes to wrap commands.
You can run these commands in a loop structure to modify multiple files. Also, instead of providing a specific date and time, you could use the current time by not providing any inputs to 'Get-Date':
>> !powershell $(Get-Item temp.m).lastwritetime=$(Get-Date)