Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort files list by date?

Tags:

r

I'm using list.files(path, pattern, full.names = TRUE) to get a list of files in a specific directory.

The files are, by default, sorted alphabetically. Is there any way in R to keep them sorted by date?

like image 511
Yann Avatar asked Dec 07 '12 11:12

Yann


People also ask

How do I sort files by date?

Click the sort option in the top right of the Files area and select Date from the dropdown. Once you have Date selected, you will see an option to switch between descending and ascending order.

How do I sort files in a list?

To sort files in a different order, click one of the column headings in the file manager. For example, click Type to sort by file type. Click the column heading again to sort in the reverse order. In list view, you can show columns with more attributes and sort on those columns.

How do you list files date wise in Linux?

ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.

How do I sort files by date in Unix?

How to list Unix files in date order? In order to ls by date or list Unix files in last modifed date order use the -t flag which is for 'time last modified'. or to ls by date in reverse date order use the -t flag as before but this time with the -r flag which is for 'reverse'.


1 Answers

You can use the file.info function to obtain details on your files. Once you have those details, you can sort the files accordingly. For example,

details = file.info(list.files(pattern="*.csv")) 

gives a data frame containing, inter alia, modification and creation times. You can sort that data frame however you want. Here I sort according to modification time, mtime:

details = details[with(details, order(as.POSIXct(mtime))), ] files = rownames(details) 
like image 122
csgillespie Avatar answered Sep 20 '22 02:09

csgillespie