Copy xxxxxxxx_xxxxxxxx.jpg from drive to folder


I’m new in this forum but also very new to powershell.
I was looking for a way to copy all my pictures from all my drives to one or more folder based on what kind of picture (phonecamera, whatsapp, facebook, etc…)
They all use a specific buildup for the filename. My current phonecamera uses [8numbers][dash][8numbers] another one uses [underscore] instead of [dash]
I tried learning some basic powershell skills first, but i get distracted by my endgoal…
I made a test setup to try stuff… but after this point i was lost in TMI
I have a source Folder with a 2 subfolders and one of them has a Subsubfolder. All of them have textfiles with the same filename patterns as the pictures im trying to copy.

and the code i have managed… (it’s not much…)

“Copy-Item D:\PowershellCopyTest\bron*.txt -Recurse -Destination D:\PowershellCopyTest\doel”

There are probably better ways of handeling what i was planning to do, but my mind was stuck on this. And it used superglue…

Thanks in advance

Hi, welcome to the forum :wave:

If the patterns are unique, then you could use a regular expression to match the filename and set the destination based on the name format. Example:

$sourceFiles = Get-ChildItem 'E:\Temp\Files\Source' -File

foreach ($file in $sourceFiles) {

    switch -Regex ($file.BaseName) {
        '\d{8}-\d{8}' { $destination = 'E:\Temp\Files\Destination1' }
        '\d{8}_\d{8}' { $destination = 'E:\Temp\Files\Destination2' }

    Copy-Item -Path $file.FullName -Destination $destination


Now you have two things to learn, PowerShell and regular expressions :slight_smile:

Thank you very much for your reply.
I did not get a notification (and i did set it, or so i thought) otherwise i would have reacted sooner.

And yes, i will have to learn a whole lot more… First of which should be organizing… to prevent sorting close to 100.000 pictures gathered from 8 devices, clouds i use with 7 different accounts, cross accounts and devices…

I will let you know how it went, after some sleep… 2am now…

But you saved my sanity and probably someones life (jk)

Good morning (for me at least morning)

I tested the script and it kind of worked.
What i would like to do is see if i can tweak it myself first. But, if it’s okay with you, maybe post a follow-up question later.
what it seems to do now is take “at least” the values specified. I am going to try to mess with ^and$ to see if that fixes anything.

I have a great startingpoint and i am very greatful for that :pray:

I am pulling my hair here…
Is it possible that my computer doesnt recognize Regex :person_shrugging:t2:
Do i have to turn that on somewhere? :person_facepalming:t2:

"^\d{8}_\d{6}" -eq "20022002_152638"
"^[0-9]{8}_[0-9]{6}" -eq "20022002_152638"
"^\d{8}_\d{6}" -Match "20022002_152638"
"^[0-9]{8}_[0-9]{6}" -Match "20022002_152638"

These all came back as False when i put them in PS

when i thought it worked i still had one foot in bed, eyes (well, one of em) open 10% capacity…

You’re doing it backwards. It’s the text that matches the pattern, not the other way around. Also -eq does not utilize regex

Can you tell i’m new to this…?

Thank you very much.