-1

I have a list of 100+ folders listed already in order.

Folder 1 Folder 2 Folder 3 etc...

In each of the folder contains images that are also in order

001.jpg 002.jpg 003.jpg etc...

Ultimately, I am trying to combine these 100+ folders into one massive folder with all the images inside according to their order, renaming each image from 000000001 - 99999999.

I am a complete beginner in coding. I have tried using Bulk Renaming Utility but i cant get it to combine all the images from multiple folders into one folder.

Any help is appreciated.

Thank you!

  • Do you want to combine all images into one folder? or Do you want to combine all folders with images into one folder? – Abdush Shakoor Mohamed Nazeer Sep 14 '19 at 09:16
  • 2
    Well, Stack Overflow is not a free coding service. Try to solve the problem yourself, write some code and if you get stuck on a certain step, feel free to ask a question about that particular problem. – Cosmin Staicu Sep 14 '19 at 09:26
  • See code below. As a `complete beginner in coding`, you have to promise to research the heart of this script which is the `get-childitem` cmdlet as well as formatting numeric values (`$targetFileNameIndex`) to be used as a string and the `Copy-Item` cmdlet. This is a pretty good source: [Powershell Tutorial](https://www.tutorialspoint.com/powershell/index.htm). Note: Since you want to rename each image 00000001 - 99999999, I assume you want to combine all images into one folder and not combine all folders with images into one folder – VA systems engineer Sep 14 '19 at 14:57
  • @CosminStaicu I have tried my own code but i did not succeed. I agree with Stack Overflow not being a free coding service. I will post a question about a stuck code after ive tried harder. Im admittedly still learning. – Daryl Chua Sep 18 '19 at 12:28
  • @MegaColorBoy sorry if i was unclear. Im trying to combine all images into one folder. – Daryl Chua Sep 18 '19 at 12:31
  • @NovaSysEng Thanks! Your answer helped alot! I will test it out. I will also take a closer look at the tutorials – Daryl Chua Sep 18 '19 at 12:32
  • You're welcome. Please accept my answer if you feel it answers your question – VA systems engineer Sep 18 '19 at 14:42

1 Answers1

0

Here's the minimum script needed to meet your requirements. There's no error checking.

Set $topSourceFolderName and $targetFolderName as needed for your computer

I assume your 100+ folders, Folder 1 Folder 2 Folder 3 etc. all exist under a single parent folder ($topSourceFolderName)

I assume the single parent folder and all of the 100+ folders under the single parent folder contain only jpg files

I assume your "one massive folder" ($targetFolderName) is NOT anywhere under the single parent folder ($topSourceFolderName)

I assume the PowerShell script is stored in a folder other than $topSourceFolderName or $targetFolderName

Email me at william.s.charlton@outlook.com if you have any questions

In my example, the PowerShell script is stored in c:\temp\bulkConsolidate.ps1

C:\Temp\massiveFolder is the target folder. It is initially empty.

C:\Temp\topFolder\Folder 1 has 001.jpg and 002.jpg

C:\Temp\topFolder\Folder 2 has 001.jpg and 002.jpg

After the script is run, C:\Temp\massiveFolder has 00000001.jpg, 00000002.jpg, 00000003.jpg, and 00000004.jpg

00000001.jpg is copied from C:\Temp\topFolder\Folder 1\001.jpg

00000002.jpg is copied from C:\Temp\topFolder\Folder 1\002.jpg

00000003.jpg is copied from C:\Temp\topFolder\Folder 2\001.jpg

00000004.jpg is copied from C:\Temp\topFolder\Folder 2\002.jpg

cls

$topSourceFolderName = "C:\Temp\topFolder"
$targetFolderName = "C:\Temp\massiveFolder"

#define empty PowerShell array 
$fullyQualifiedJpgSourceFileNameList = @()

#get fully-qualified file name (FullName) for all files in and below $topFolderNmae
$fullyQualifiedJpgSourceFileNameList = @((Get-ChildItem -recurse -LiteralPath $topSourceFolderName -File) | Select -Property FullName | sort -Property FullName)

#Copy each file to the single target directory, renaming each file as it is copied

$targetFileNameIndex = 0

foreach ($fullyQualifiedJpgSourceFileName in $fullyQualifiedJpgSourceFileNameList)
{
    #create fully qualified target file name for this jpg file
    #format $targetFileNameIndex so it has 8 leading digits
    #https://devblogs.microsoft.com/scripting/hey-scripting-guy-how-can-i-use-leading-zeroes-when-displaying-a-value-in-windows-powershell/
    $fullyQualifiedJpgTargetFileName = ($targetFolderName + "\" + $targetFileNameIndex.ToString("00000000") + ".jpg")

    #increment index for next jpg file copy
    $targetFileNameIndex = ($targetFileNameIndex + 1);

    Copy-Item -LiteralPath $fullyQualifiedJpgSourceFileName.FullName -Destination $fullyQualifiedJpgTargetFileName -Force
}
VA systems engineer
  • 2,856
  • 2
  • 14
  • 38