Get most recent file in a directory on Linux
ls -Art | tail -n 1
Not very elegant, but it works.
Used flags:
-A
list all files except .
and ..
-r
reverse order while sorting
-t
sort by time, newest first
Get second newest file in a folder
Looks like you actually want getmtime
, not getctime
(since you're showing us a screenshot showing modification times).
python: How to get latest file in a directory with certain pattern
You could simply go like this:
def newest(DIR_PATH):
files = os.listdir(DIR_PATH)
FILE_LIST = [os.path.join(DIR_PATH, BASENAME) for BASENAME in files if not BASENAME.endswith("trimmed.json")]
return max(FILE_LIST, key=os.path.getctime)
Powershell: Get-ChildItem, get latest file of files with similar names
Ok, now that you've provided the whole list that you filter against I can write up a real answer. Here we'll group by file name, then sort each group and grab the last one from each group:
Get-ChildItem -Path c:\tm1 |
Where-Object { $_.Name -match '^RR_Prognos.*|^AllokeringBogNycklar.*|^Aktivversion.*|^AllokeringNycklar.*|^HR_prognos.*|^KostnaderDK.*|KostnaderProdukt_prognos.*|^Parametrar_prognos.*|ProduktNyckel_prognos apr.*' } |
Group {$_.Name -replace '.*?(^RR_Prognos|^AllokeringBogNycklar|^Aktivversion|^AllokeringNycklar|^HR_prognos|^KostnaderDK|KostnaderProdukt_prognos|^Parametrar_prognos|ProduktNyckel_prognos apr).*','$1'} |
ForEach-Object {
$_.Group |
Sort-Object -Property LastWriteTime -Descending |
Select -First 1
} |
Select-Object LastWriteTime,FullName
Related Topics
Windowserror: [Error 126] the Specified Module Could Not Be Found
Psycopg2 Insert Python Dictionary as Json
Is There a Memory Efficient and Fast Way to Load Big Json Files
Importerror: No Module Named Bs4 (Beautifulsoup)
Finding the Two Closest Numbers in a List Using Sorting
Find All CSV Files in a Directory Using Python
How to Increase the Font Size of the Markdown Table in Jupyter Notebook
Using Beautifulsoup to Extract Text from Div
How to Easily Print Ascii-Art Text
Fill With Nan When Length of Values Does Not Match Length of Index
Use Tqdm Progress Bar With Pandas
Python - How to Check If Table Exists
Deleting Dataframe Row in Pandas If a Combination of Column Values Equals a Tuple in a List
Running Two Python Scripts With Bash File
How to Correct Typeerror: Unicode-Objects Must Be Encoded Before Hashing
How to Hide Tkinter Python Gui
How to Replace Negative Numbers in Pandas Data Frame by Zero