Powershell script for moving sample mkvs into folder
Posted: October 5th, 2021, 4:24 am
Hi,
I am new at scripting but have started working on a script in Windows 10 for moving files in releasefolders named *sample*.mkv into a Sample folder. Because this functionality is not built into sabnzbd I believe?
I have one version of the script that works when launching it in the local releasefolder so to speak outside of sabnzbd.
E.G: Place saample.ps1 in c:\test\Very.l33t.2021.CAM.VCD-NOGRP and run it and it creates the Sample folder if not found and moves *sample*.mkv into it.
That looks like this:
I then tried modifying it a bit and tying it together with sabnzbd using a wrapper batchfile (.bat) that looks like this:
The above saample.ps1 used in the .bat:
However, when running this it just created C:\Sample and exits.
And if running it again I get "Sample already found", so that part works...
Can somebody point me in the right direction? I am not sure at all at how to use SAB_FINAL_NAME & %3 properly here.
I just found python examples here: https://sabnzbd.org/wiki/scripts/post-p ... s#env_vars
Batch to powershell maybe adds an extra layer of complexity?
Worst case scenario; if noone has any input maybe you even have a working script I can use?
Thanks
I am new at scripting but have started working on a script in Windows 10 for moving files in releasefolders named *sample*.mkv into a Sample folder. Because this functionality is not built into sabnzbd I believe?
I have one version of the script that works when launching it in the local releasefolder so to speak outside of sabnzbd.
E.G: Place saample.ps1 in c:\test\Very.l33t.2021.CAM.VCD-NOGRP and run it and it creates the Sample folder if not found and moves *sample*.mkv into it.
That looks like this:
Code: Select all
$local = Get-Location
$File = Get-ChildItem -Path $local\*sample*.mkv
$Folder = "$local\Sample"
$Folder2 = "$local\SAMPLE"
if( ( ( Test-Path $Folder ) -or ( Test-Path $Folder2 ) ) )
{
"Sample already found"; break
}
else
{
New-Item -Path $Folder -ItemType "directory"
Move-Item -Path $File -Destination $Folder
}
Code: Select all
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Script\saample.ps1" -SAB_FINAL_NAME "%3"
Code: Select all
$File = Get-ChildItem -Path "$SAB_FINAL_NAME\*sample*.mkv"
$Folder = "$SAB_FINAL_NAME\Sample"
$Folder2 = "$SAB_FINAL_NAME\SAMPLE"
if( ( ( Test-Path $Folder ) -or ( Test-Path $Folder2 ) ) )
{
"Sample already found"; break
}
else
{
New-Item -Path $Folder -ItemType "directory"
Move-Item -Path $File -Destination $Folder
}
And if running it again I get "Sample already found", so that part works...
Can somebody point me in the right direction? I am not sure at all at how to use SAB_FINAL_NAME & %3 properly here.
I just found python examples here: https://sabnzbd.org/wiki/scripts/post-p ... s#env_vars
Batch to powershell maybe adds an extra layer of complexity?
Worst case scenario; if noone has any input maybe you even have a working script I can use?
Thanks