Where this code required?

In many scenario, we will got the requirement for moving the specific files from the large number of files from one location to another location based someย filterย  on the file name. This code will helps with same situation. The below code will split the filename before “-” and compare the existing list “filterLists” to findย 

STEP #1

Declare the souce and target path locations.

$srcpath = “C:\Powershelltest\Source”
$dstpath = “C:\Powershelltest\Destination”

STEP #2

Fetch all the child file list to make the loop to start the validation of each files.

$fileList = Get-ChildItem -Path $srcpath -Force -Recurse
foreach ($file in $fileList)
{
}

STEP #3

Second level of loop for validating whether filename is mathing with our input

foreach($filelist in $filterLists)
{
#Our Logic
}

Complete Code

Output

After Execution

What do you think?

I hope you have an idea ofย  Move files to another directory Based on Filename with Powershell. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.