To use utimesSync
function from fs-extra
library in TypeScript, you need to import the fs-extra
module and use the utimesSync
function like this:
index.ts344 chars13 lines
In this example, we imported fs-extra
module using import * as fs from 'fs-extra';
. We then defined the filePath
and mtime
variables. filePath
is the path to the file whose modified time we want to update, and mtime
is a Date object representing the new modified time.
We then call the fs.utimesSync()
function with the file path and the new modified time twice, as it takes two arguments representing the access time and modified time of the file respectively. In this case, we update the access time as well to the same value as the modified time.
We use a try-catch block to handle errors. If the function call is successful, we log a success message to the console. Otherwise, we log an error message along with the error object to the console.
Make sure to have the fs-extra
module installed in your project by running npm install fs-extra
.
gistlibby LogSnag