I am trying to first of all detect if one specifik folder is having any files *.xml so far so good.
Now to my problem. There is multiple folders and under them there are one error folder and if that error folder is holding any *.xml that shall be moved to another directory above error directory.
And if that new folder don’t exists that shall be created and then the *.xml file shall be moved to that place.
So far i have this for control and to create but I always get NULL. All the other stuff is working fine.
Do you know the name of the folder in advance? Is *test* the name pattern for the folder? When you’re looking for folders you should specify trhe parameter -Directory for your Get-ChildItem command. Will the XML files have a name or at least a part of their name you know in advance?
If there is no such folder your result variable $Folder is empty or not existing. You should test for these properties before you test the existence with Test-Path. ( mehtod .IsNullOrEmpty() )
When you post error messages you should format them as code as well.
It’s hard to explain.
The code to see * .xml files works and that it is only in the directory error it should check also works.
The problem is when there is a * .xml file in the directory it should be moved to another directory but if that directory is missing it should be created first and then the * .xml file should be moved to the newly created directory.
The new directory will be created on the same level as the error directory where there are already three directories including the error directory.
So you check first if this desired target directory exists with Test-Path. If it does not exist you create it with New-Item.
When you successfully created the target directory or if it’s already there you use Move-Item to move the needed files to the target folder.