Skip to content

Instantly share code, notes, and snippets.

@bspavel
Created March 5, 2019 20:17
Show Gist options
  • Save bspavel/3c3a9b7fe7d5a72c5c7761c72763ddd2 to your computer and use it in GitHub Desktop.
Save bspavel/3c3a9b7fe7d5a72c5c7761c72763ddd2 to your computer and use it in GitHub Desktop.
#https://stackoverflow.com/questions/1523043/how-to-loop-through-files-and-rename-using-powershell
#https://stackoverflow.com/questions/2038181/how-to-output-something-in-powershell
#https://stackoverflow.com/questions/15113413/how-do-i-concatenate-strings-and-variables-in-powershell
#https://habr.com/ru/post/242445/
#https://stackoverflow.com/questions/39761059/display-file-names
#https://windowsnotes.ru/powershell-2/powershell-i-regulyarnye-vyrazheniya-chast-1/
cls;
$files = Get-ChildItem $(pwd) -Filter *.mp4| select BaseName;
foreach($f in $files)
{
if(
[string]$f -match "BaseName\=(?'gname'(?:variant1|variant2|variant3).?(?'number'[\d]+)(?:.?\-.?)(?'name'.*))\}"
){
$name = [string]$Matches['name'];
$number = [int]$Matches['number'];
$gname = [string]$Matches['gname'];
if( ($number -ge 1) -and ($number -le 9) ){
$nm="000"+$number;
}elseif( ($number -ge 10) -and ($number -le 99) ){
$nm="00"+$number;
}elseif($number -ge 100){
$nm="0"+$number;
}
Write-Output $gname".mp4";
Write-Output $nm"___"$name;
#
#
#Rename-Item $gname".mp4" -NewName $nm"___"$name".mp4";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment