Hi, this is my first post here. I was looking around for a way to trim NDS roms simply, and I couldn't find anything other than the command-line trim.exe by ratx, which can't trim in place (results in 2 files) and I wanted to save myself some time. I've been learning Windows Powershell lately so I figured it would be a good way to achieve this goal.
Here is a powershell script to invoke trim.exe on all roms in a directory, and if the trim was successful it will delete the old rom and rename the new one to the old name. As it is written it looks for trim.exe in the current directory, but this can be easily changed as I mentioned in the comments. Remember that running powershell scripts is disabled by default, so you will have to enable them in the following way before you can use this command inside powershell:
Set-ExecutionPolicy RemoteSigned
This allows local scripts to be run but restrict unsigned remote scripts. Here is the code:
(it doesn't appear that I can attach files, so save this text in a .ps1 file)
CODE##################################################
# Written by Brian Cumminger #
# Jan 23rd, 2009 #
# Under no license, do whatever you want with it #
##################################################
#trim-and-rename.ps1
#get all roms and loop through them
$files = Get-ChildItem *.nds
#path to trim.exe, to specify a location other than the current directory,
#replace (Get-Location).Path with "c:\nds\apps" to use c:\nds\apps\trim.exe
$curdir = (Get-Location).Path
foreach ($file in $files) {
$fname = $file.FullName
$fstartname = ('"' + $fname + '"')
#run trim.exe and wait for it to finish
$trimproc = [diagnostics.process]::start(($curdir + "\trim.exe"), $fstartname)
$trimproc.WaitForExit()
#generate name that the trimmed file will have
$trimmedfilename = ($file.FullName.Substring(0,($file.FullName.Length-4)) + '.trim.nds')
#if trimming was successful...
$didTrim = Test-Path ($trimmedfilename)
if ($didTrim -eq "True") {
#delete old untrimmed file and rename new trimmed version
$newfile = Get-ChildItem ($trimmedfilename)
$file.Delete()
$newfile.MoveTo($fname)
}
}
Trim.exe: ratx's blog
Powershell: Microsoft's Powershell Site
Here is a powershell script to invoke trim.exe on all roms in a directory, and if the trim was successful it will delete the old rom and rename the new one to the old name. As it is written it looks for trim.exe in the current directory, but this can be easily changed as I mentioned in the comments. Remember that running powershell scripts is disabled by default, so you will have to enable them in the following way before you can use this command inside powershell:
Set-ExecutionPolicy RemoteSigned
This allows local scripts to be run but restrict unsigned remote scripts. Here is the code:
(it doesn't appear that I can attach files, so save this text in a .ps1 file)
CODE##################################################
# Written by Brian Cumminger #
# Jan 23rd, 2009 #
# Under no license, do whatever you want with it #
##################################################
#trim-and-rename.ps1
#get all roms and loop through them
$files = Get-ChildItem *.nds
#path to trim.exe, to specify a location other than the current directory,
#replace (Get-Location).Path with "c:\nds\apps" to use c:\nds\apps\trim.exe
$curdir = (Get-Location).Path
foreach ($file in $files) {
$fname = $file.FullName
$fstartname = ('"' + $fname + '"')
#run trim.exe and wait for it to finish
$trimproc = [diagnostics.process]::start(($curdir + "\trim.exe"), $fstartname)
$trimproc.WaitForExit()
#generate name that the trimmed file will have
$trimmedfilename = ($file.FullName.Substring(0,($file.FullName.Length-4)) + '.trim.nds')
#if trimming was successful...
$didTrim = Test-Path ($trimmedfilename)
if ($didTrim -eq "True") {
#delete old untrimmed file and rename new trimmed version
$newfile = Get-ChildItem ($trimmedfilename)
$file.Delete()
$newfile.MoveTo($fname)
}
}
Trim.exe: ratx's blog
Powershell: Microsoft's Powershell Site