I have a script that is designed to do three things:
- Convert all .webp files to .jpg from the main "Test" and all its differently-titled subfolders.
- For each directory, make a sub directory called "Ch1" within.
- Move all the files into the "Ch1" folder
The script currently looks like this, and works fine for single-titled folders with only .webp or .jpg files in each:
cd D:\TestingGrounds\Test
get-childItem -recurse | Where {$_.extension -eq ".webp"} | rename-item -newname {$_.name -replace ".webp",".jpg"}
$dirs = Get-ChildItem -force D:\TestingGrounds\Test
foreach ($dir in $dirs) {mkdir D:\TestingGrounds\Test\$dir\ch_1; move D:\TestingGrounds\Test\$dir\* D:\TestingGrounds\Test\$dir\ch_1}
I now have multi-chapter folders that already have subfolders with .webp and .jpg files inside pre-made chapter folders, such as "Ch1", "Ch1.5", "Ch2", etc.
I cannot figure out a way to add an exception or exclusion to these multi-chapter folders where they are not touched by the mkdir
and move
portions, only all .webp files to still be renamed
to .jpg
I'm not very familiar with Powershell, much less exception commands. I've tried -notcontains, Where-Object, and making another designator, like $multi = 'Ch*' to be ignored. So far, nothing has worked. It will continue to make a "Ch1" in the multi-chapter subfolders except for the original "Ch1", and move their respective files into them... basically what the original script did. Attached are photos of what I'm trying to do. 1 Before 2 Desired Outcome
Here are some of my attempts:
$dirs = Get-ChildItem -force 'D:\TestingGrounds\Test';
$Multi = 'Ch*';
get-childItem -recurse | Where {$_.extension -eq ".webp"} | rename-item -newname {$_.name -replace ".webp",".jpg"};
if ($folder -notcontains 'Ch*') {mkdir D:\TestingGrounds\Test\$folder\Ch1; move D:\TestingGrounds\Test\$folder\* D:\TestingGrounds\Test\$folder\Ch1}
{mkdir D:\TestingGrounds\Test\$folder\Ch1; move D:\TestingGrounds\Test\$folder\* D:\TestingGrounds\Test\$folder\Ch1} | Where {D:\Testing Grounds\Test\$dir\ -notcontains 'Ch*'}
gci "D:\TestingGrounds\Test" | Where-Object {$_.FullName -notlike "Ch*"} | mkdir D:\TestingGrounds\Test\$dir\Ch1; move D:\TestingGrounds\Test\$dir\Ch1\* D:\TestingGrounds\Test\$dir\Ch1; move D:\TestingGrounds\Test\$dir\Ch1 D:\TestingGrounds\Test\$dir
$dirs = Get-ChildItem -force D:\TestingGrounds\Test; $Multi = 'Ch*'; get-childItem -recurse | Where {$_.extension -eq ".webp"} | rename-item -newname {$_.name -replace ".webp",".jpg"}; if ($dir -notcontains $Multi) {mkdir D:\Testing Grounds\Test\$dir\Ch1; move D:\Testing Grounds\Test\$dir\* D:\Testing Grounds\Test\$dir\Ch1}