I need to sort through many folders (all in the same directory) to move and rename all the JPGs as "parentfolder" + "#", where "parentfolder" is the parent folder name and "#" is a consecutive label for each group of files in their respective folder.
For example, in the folder .\Input\MainID1 is a.jpg, b.jpg, c.jpg and some other file types. In another folder .\Input\MainID2 is also a.jpg, b.jpg, c.jpg and some other file types.
A desired output would be to save all the jps in a single folder renamed as:
File Path New File name MainID1\a.jpg MainID1_1 MainID1\b.jpg MainID1_2 MainID1\c.jpg MainID1_3
Then have the loop reset when looking in the next folder to allow for:
File Path New File name MainID2\a.jpg MainID2_1 MainID2\b.jpg MainID2_2 MainID2\c.jpg MainID2_3
I'm having trouble finding a way to restart the loop for each individual folder. Currently, my loop is iterating the entire directory's .jpg files.
C:\Users\Rango\Renaming\Input> Get-ChildItem -Recurse -Filter *.jpg |
ForEach-Object {$c = 1}
{Write-Host $_.Directory.Name $c; $c++}
{ $c = 1}
Output:
Main ID 1 1 Main ID 1 2 Main ID 1 3 Main ID 1 4 Main ID 10 5 Main ID 10 6 Main ID 10 7 Main Id 100 8 Main Id 101 9 Main Id 102 10 Main Id 102 11 Main Id 102 12 Main Id 102 13 Main Id 102 14 Main Id 102 15 Main Id 102 16 Main Id 102 17 Main Id 102 18 Main Id 102 19 Main Id 102 20 Main Id 102 21 Main Id 102 22 Main Id 103 23 Main Id 104 24 Main Id 104 25 Main Id 105 26 Main Id 105 27 Main Id 106 28 Main Id 107 29 Main Id 109 30 etc.