-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_file_dates.ps1
25 lines (21 loc) · 1.06 KB
/
update_file_dates.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Get a listing of all the Markdown files within the given folder and all subfolders.
# modified from: https://forum.obsidian.md/t/preserve-creation-dates-when-using-obsidian-sync/24818/5
param ( $Dir = '.')
$files = Get-ChildItem $Dir -Recurse -Name -Filter "*.md"
foreach ($file in $files) {
$file = $Dir + "\" + $file
$createdDate = Get-Content -LiteralPath $file | Select -Index 3
$createdDate = $createdDate -replace 'created: ',''
if ([string]$createdDate -as [DateTime]) {
$(Get-Item -LiteralPath $file).creationtime=$("$createdDate")
}
else { Write-Host "Error setting creation date for: $file" }
$modifiedDate = Get-Content -LiteralPath $file | Select -Index 2
$modifiedDate = $modifiedDate -replace 'updated: ',''
if ([string]$modifiedDate -as [DateTime]) {
$(Get-Item -LiteralPath $file).LastWriteTime=$("$modifiedDate")
}
else { Write-Host "Error setting modification date for: $file" }
}
Write-Host "Finished running. Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")