I would like to create a script which creates just 1 folder for each exampe and move all 3 files there.
I was able to create a script which uses the example1.pd to create a folder named example1 and that for all of the ongoing numbers.
But I am having problems to let the other files, named _COT, _en to be moved into that folder.
I first tried a script which can move files with the same filename into a folder with the same file names. The script would check for the first 50 characters of the file name. But then of course it wont copy the files with the post-fixes.
I then tried to include in the script a function to exclude “_COT and _en” and move it then. But it wont work.
Does someone has an Idea how a script like that can look like?
I have attached my current script
Since the “suffixes” of your filenames are connected with an underline you can split there and use this as the common property. This should be enough actually:
So i tried using this script to move the files from the source folder into the destination folder.
and that all example1*.pdf should move into folder example1, so that in the destination folder all 3 would be present.
Of course you have to adjust it to your environment. I assumed example1.pdf was just an example. So you have to provide a valid -Filter criteria for your Get-ChildItem command:
Instead of "filename*" you should use "example*" or you remove the -Filter completely when there are no other files in that forlder.
And BTW: Please format your code or sample data as code. Thanks in advance.
I have found a workaround.
First i let the script search for all filenames in that folder and create for each file a folder, but exclude the files which end with “_COT” or “_en”. After that I let the script search the source folder for filenames, which include the folder names and move them into that specific folder
I had some problems with my adapted script - for the filenames I use have lots of “_” in it. So while I was waiting for your response I started to try different approaches.
Since my filenames have 3-5 “_” in it, the script cut off at different places and created a lot if folders, which I could not use as desired :)! But I think it would work out fine if the filenames are simpler! Thanks for looking into it. I still try to find out how Powershell thinks and how I should approach different
Hmmm … and why don’t you share some example file names having the same structure your real files names have???
The help we can provide heavily depends on the information we get.
And what’s the criteria to split? Or in other words what part would you like to use?
And with “different places” you mean all underlines, right?
If that’s an option I’d try this approach. But there might a way to accomplish what you need but you don’t see yet. So you show what you have to deal with. Maybe one of us has an idea.
Lucky you that it does not. It’s a computer. It does not think. It computes.