TidyBatch

How to add the date to file names in bulk

Turn invoice.pdf into 2024-08-12_invoice.pdf for hundreds of files at once, so they sort by date anywhere. Use YYYY-MM-DD: it's the only format that sorts correctly as plain text.

First, pick the right date

DateWhat it isUse it for
ModifiedWhen the file was last changed. Copying between drives or downloading can reset it.Documents, invoices, exports
Date taken (EXIF)Stored inside photos by the camera or phone. Survives copying.Photos and many videos
TodayWhen you run the rename."Received on" batches

Windows: PowerShell (modified date)

# Preview with -WhatIf; remove it to apply
Get-ChildItem -File | Rename-Item -NewName { $_.LastWriteTime.ToString('yyyy-MM-dd') + '_' + $_.Name } -WhatIf

Linux: bash (modified date)

With GNU date (standard on Linux), date -r FILE prints the file's modification time. mv -n never overwrites:

# Preview (echo), then remove "echo" to run
for f in *; do [ -f "$f" ] && echo mv -n -- "$f" "$(date -r "$f" +%F)_$f"; done

Photos: exiftool (date taken)

For photos, the free ExifTool is the standard. It reads the real "date taken" and its %-c adds a counter when two photos share the same second:

# Preview: show the new names without renaming
exiftool -d '%Y-%m-%d_%H%M%S%%-c.%%e' '-TestName<DateTimeOriginal' .

# Apply
exiftool -d '%Y-%m-%d_%H%M%S%%-c.%%e' '-FileName<DateTimeOriginal' .

Any OS: TidyBatch (modified date, with undo)

TidyBatch uses Python-style date formats in its template. It previews by default and can undo afterwards:

tidybatch rename ./invoices -t "{date:%Y-%m-%d}_{stem}{ext}"           # preview
tidybatch rename ./invoices -t "{date:%Y-%m-%d}_{stem}{ext}" --apply   # apply
tidybatch undo ./invoices                                             # revert

Other fields work too, e.g. a counter in date order: tidybatch rename ./scans --sort date -t "scan_{n:03}{ext}". For photos, use {taken} instead of {date} to get the EXIF date taken: see rename photos by date taken.

Related: can you undo a bulk rename? →

Related: bulk rename files safely →