Hoi allen, ik ben bezig met een PS script te schrijven om files te moven van uit de root naar bestaande of nieuwe subdirectories aan de hand van bepaalde cijfers in de betstandsnaam.
Het PS script is zo goed als klaar maar ik vind niet hoe ik een bepaalde cijfers uit de bestandsnaam kan opslaan in een variable.
PS script:
De filenames zijn opgebouwd als volgt:
blablabla_117012789090.png
Hiervan heb ik cijfer 2 & 3 nodig voor het jaar en cijfer 4 & 5 voor de maand. Dus als regex heb ik:
jaar: .*_\d\d\d(\d{2})\d*
maand: .*_\d\d\(\d{2})\d*
Alleen vind ik nu niet hoe ik deze in $year & $month variable moet krijgen.
Kan me iemand even de juiste richting uitduwen?
Het PS script is zo goed als klaar maar ik vind niet hoe ik een bepaalde cijfers uit de bestandsnaam kan opslaan in een variable.
PS script:
PowerShell:
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
| $root = "\\fqdn\share" $files = Get-ChildItem -Path $root ForEach ($file in $files) { $year = $file.regexfilter $month = $file.regexfilter $dir_path = Join-Path -Path $root -ChildPath $year $dir_path_month = Join-Path $dir_path -ChildPath $month $letters = $file.BaseName[0..2] -join "" $dir_sub_full = Join-Path -Path $dir_path_month -ChildPath $letters If (!(Test-Path $dir_path)) { New-Item -Path $root -Name $year -ItemType Directory } If (!(Test-Path $dir_path_month)) { New-Item -Path $root\$year\ -Name $month -ItemType Directory } If (!(Test-Path $dir_sub_full)) { New-Item -Path $root\$year\$month -Name $letters -ItemType Directory } Move-Item -Path $file.FullName -Destination $dir_sub_full } |
De filenames zijn opgebouwd als volgt:
blablabla_117012789090.png
Hiervan heb ik cijfer 2 & 3 nodig voor het jaar en cijfer 4 & 5 voor de maand. Dus als regex heb ik:
jaar: .*_\d\d\d(\d{2})\d*
maand: .*_\d\d\(\d{2})\d*
Alleen vind ik nu niet hoe ik deze in $year & $month variable moet krijgen.
Kan me iemand even de juiste richting uitduwen?