Powershell Rom Trimming Script

Discussion in 'NDS - Flashcarts and Accessories' started by BrianCumminger, Jan 23, 2009.

Jan 23, 2009
  1. BrianCumminger
    OP

    Newcomer BrianCumminger Newbie

    Joined:
    Jan 23, 2009
    Messages:
    1
    Country:
    Canada
    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
     
  2. blainy

    Member blainy GBAtemp Fan

    Joined:
    Nov 1, 2008
    Messages:
    381
    Location:
    australia
    Country:
    Australia
    why would we need to use your script when NDS Tokyo Trim does the job perfectly?? especially as you have a post count of 1..
     
  3. TrolleyDave

    Former Staff TrolleyDave Philosolosophising

    Joined:
    Jan 1, 2007
    Messages:
    7,762
    Location:
    Wales, UK
    Country:
    United Kingdom
    And what about for the people that don't want to use TokyoTrim? As great of a trimmer as it is there are still people that prefer to use other trimmers.
     
  4. Evilmaster1985

    Member Evilmaster1985 GBAtemp Fan

    Joined:
    Nov 23, 2008
    Messages:
    456
    Location:
    Middle of nowhere
    Country:
    United States
    I like my NDS Rom Trimmer v0.22a.
    Drag and drop [​IMG]
    No trouble with wifi or multiplayer what so ever.
    Trimmed over 10gb of NDS roms with it that are in use on my NDS now [​IMG]

    Greetz, Vistabuser.
     
  5. blainy

    Member blainy GBAtemp Fan

    Joined:
    Nov 1, 2008
    Messages:
    381
    Location:
    australia
    Country:
    Australia

    i probably shouldn't have been so specific by mentioning NDSTokyo trim, but you know what i meant....why would we trust some code written by sumone with no history on the forums here at all, when there are other tools that do the job perfectly..
     

Share This Page