List file in a folder but also search for sign in the filename

My first post here and I need a little help
I have work a little with powershell before and also other programming language but
have problem to start to do something basic.

I have now a bat file that I run to do some working for me but I like to upgrade it to powershell because I need to do a little
advance search for sign in the file name.

Is it possible to easy search for a specific file extension (not the subfolders) and then run a loop for each file (it going to run some commands for each file) but first I want to see if the file have sign in the filename.

Example if the file is name “hello_world_one.ts” then it run this commands, and if the file have name “hello_world.ts” it going to run some anothers commands. it look for the word “one” to decide what commands to run and it can also be more then one sign it going to look after.

Yes of course, all of the above are possible. You would require below cmdlets to achieve it.

Get-ChildItem, read the online help doc by executing Get-Help Get-ChildItem -Online, take a look at -Filter parameter as well.

ForEach-Object, read the online help doc by executing Get-Help ForEach-Object -Online.

There are examples provided for both the help docs which will help you to put up some code. You can update this thread when getting stuck/errors.

Ahh thanks alot.

Now I know what to look for I have almost got it to work.

I trying to use mkvmerge to merge a ts and srt file to a mkv file.

The original code was this

[pre] C:\Program Files (x86)\MKVToolNix\mkvmerge" -o E:\TV\TS\klar%%~nA.mkv E:\TV\TS\klar%%~nA.ts “–language” “0:swe” “–forced-track” “0:yes” E:\TV\TS\[/pre]

and I know I can use & to run a command and I use Write-Host to see what output the command show me

[pre] $myfile = “C:\Program Files (x86)\MKVToolNix\mkvmerge -o E:\TV\TS\klar$.BaseName.mkv E:\TV\TS\klar$.BaseName.ts --language 0:swe --forced-track 0:yes E:\TV\TS\klar$”
Write-Host $myfile [/pre]

but basename does not work. I does work if just do

[pre] Write-Host $_.BaseName[/pre]

But when I run my code it show fullname instead just the name of the file


Hmm I think I almost got it to work
[pre]$myfile = “C:\Program Files (x86)\MKVToolNix\mkvmerge -o E:\TV\TS\klar” + $.BaseName + “.mkv E:\TV\TS\klar” + $.BaseName + “.ts --language 0:swe --forced-track 0:yes E:\TV\TS\klar” + $_.BaseName + “”[/pre]

Now it show right but I have to somehow quote “C:\Program Files (86)\MKVToolNix\mkvmerge” in the variable?