-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ps1
38 lines (27 loc) · 1.04 KB
/
main.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
26
27
28
29
30
31
32
33
34
35
36
37
38
# Setze den Pfad zu dem Ordner, den du durchlaufen möchtest
$folderPath = "C:\Users\ewald\zettelkasten - Kopie"
# Hole alle Dateien im Ordner
$files = Get-ChildItem -Path $folderPath -File | Sort-Object CreationTime
$counter = 0
foreach ($file in $files) {
# Prüfe, ob der Dateiname kein '#' enthält
if ($file.Name -notmatch "#") {
# Hole das Erstellungsdatum der Datei
$creationDate = $file.CreationTime
if($lastCreationTime=$creationDate){
$counter++
}else{
$counter = 0
}
$lastCreationTime=$creationDate
echo $creationDate
# Formatiere das Erstellungsdatum als string
$formattedDate = $creationDate.ToString("yyMMdd")
# Baue den neuen Dateinamen
$newName = "$formattedDate-$counter#$($file.Name)"
# Setze den vollständigen Pfad für die Umbenennung
$newPath = Join-Path -Path $folderPath -ChildPath $newName
# Benenne die Datei um
Rename-Item -Path $file.FullName -NewName $newPath
}
}