Testing strings against filepaths

Basically, I am trying to split a filename and grab a number off of it and if that number is in the directory name of a static share, then move files into that directory. Kind of like a sorting script.

Here is what I have tried:

 $localshare = 'S:' $localdir = 'F:Nightly' Get-ChildItem $localshare -Filter * | foreach {$directoryName = $_.Name $ID,$comp = $_.Name.Split("_") } 

I won’t share what I have next because it is basically a bunch of commented out attempts that don’t work, but with what I have, is it possible to take $ID in this loop and test it against a bunch of directories to see if they contain this ID, and then if they do, execute a function?

I’m still kind of new to powershell, be gentle.

Edit: some example filenames being split are 10_companyname, 12_companyname, 137_companyname. However the directories I’m trying to test against just need to contain the same number as one of the IDs.

submitted by /u/RANDY_MAYONNAISE
[link] [comments]

Leave a Reply