To find the creation date of a csv file in R, you can use the function file.info()
to retrieve the metadata of the file, including its creation date. Here's an example:
main.r450 chars15 lines
In this example, file.info()
takes the path of the csv file as an argument and returns a named list that includes various metadata of the file, such as its size, access time, modification time, etc. We use the ctime
element of the list, which represents the inode change time of the file and is the closest we can get to the creation time of the file in Unix-like systems.
We then convert the ctime
value to a POSIXct object using as.POSIXct()
, with the origin set to "1970-01-01", which is the epoch time commonly used in Unix systems. We format the POSIXct object into a human-readable date and time string using format()
and print the result.
Note that the format of the date and time string can be changed to match your preferred format.
gistlibby LogSnag