This topic contains 2 replies, has 2 voices, and was last updated by
August 13, 2019 at 5:54 pm #170614ParticipantTopics: 1Replies: 1Points: -6Rank: Member
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.
August 13, 2019 at 5:58 pm #170635Senior ModeratorTopics: 8Replies: 1004Points: 3,255Rank: Community Hero
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.
August 13, 2019 at 7:18 pm #170644ParticipantTopics: 1Replies: 1Points: -6Rank: Member
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
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\klar\%%~nA.swe.srt
and I know I can use & to run a command and I use Write-Host to see what output the command show me
$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.swe.srt" Write-Host $myfile
but basename does not work. I does work if just do
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
$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 + ".swe.srt"
Now it show right but I have to somehow quote "C:\Program Files (86)\MKVToolNix\mkvmerge" in the variable?
You must be logged in to reply to this topic.