Tomasz Bojarski
asked on
Sort and copy files based on parts of the name using PowerShell
I have a task to write a PS script in order to sort and copy files into specific folders based on their name.
Files are named following convention of:
DNK - FB - YouSee - S -AFC - R- S-Default-2017-10-05.csv
NOR - FB - YouSee - S -AFC - R- S-Default-2017-10-05.csv
Meaning behind the parts of the file name:
<Country>-<Service>-<Compa ny> - rest does not really matter.
Folders however follow structure of:
D:\FB\DNK\YouSee\
D:\FB\NOR\YouSee\
Question:
What's the best way to sort and place the files in respective folders based on the first three parts of the name (Country-Service-Company?
Any help/suggestions appreciated.
Thanks
Tom
Files are named following convention of:
DNK - FB - YouSee - S -AFC - R- S-Default-2017-10-05.csv
NOR - FB - YouSee - S -AFC - R- S-Default-2017-10-05.csv
Meaning behind the parts of the file name:
<Country>-<Service>-<Compa
Folders however follow structure of:
D:\FB\DNK\YouSee\
D:\FB\NOR\YouSee\
Question:
What's the best way to sort and place the files in respective folders based on the first three parts of the name (Country-Service-Company?
Any help/suggestions appreciated.
Thanks
Tom
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Yes, let me adjust for that...
»bp
»bp
There are never spaces embeded in those folder names, is that true? Just before or after...
»bp
»bp
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Many thanks Bill.
This little script did the trick.
Regards
Tom
This little script did the trick.
Regards
Tom
Welcome, glad that was helpful.
»bp
»bp
ASKER
Works like a charm!
This is exactly what I needed. Is there a way to ignore the spaces in the file names so that folder names are created without them?
Currently folder names include the spaces from original file names. I could ask the app owner to make sure they use correct naming convention but chances are they will forget at some point.
Tom