tags:

views:

26

answers:

1

Hi everyone,

I just picked up IronPython and I've been trying to get this IronPython script going but I'm stuck at trying to get a Path input from raw_input to be a directory path. The first block of code is the broken one that I'm working on.

import System
from System import *
from System.IO import *
from System.Diagnostics import *

inputDirectory = raw_input("Enter Input Directory's full path [eg. c:\\vid\\]: ")
print ("In: "+inputDirectory)
outputDirectory = inputDirectory +"ipod\\"
print ("Out: "+outputDirectory)
#create the default output directory

for s in DirectoryInfo(inputDirectory).GetFiles("*.avi"): 
print s.FullName
    arg = String.Format('-i "{0}" -t 1 -c 1 -o "{1}" --preset="iPod"' , s.FullName, outputDirectory + s.Name.Replace(".avi", ".mp4"))
    print arg
    proc = Process.Start("C:\\Program Files\\Handbrake\\HandBrakeCLI.exe", arg) #path to handbrake goes here
    proc.WaitForExit()

The following code block is what I have working at the moment.

import System
from System import *
from System.IO import *
from System.Diagnostics import *

for s in DirectoryInfo("F:\\Tomorrow\\").GetFiles("*.avi"): 
    arg = String.Format('-i "{0}" -t 1 -c 1 -o "{1}" --preset="iPod"' , s.FullName, "F:\\Tomorrow\\ipod\\" + s.Name.Replace(".avi", ".mp4"))
    print arg
    proc = Process.Start("C:\\Program Files\\Handbrake\\HandBrakeCLI.exe", arg) #path to handbrake goes here
    proc.WaitForExit()

PS: Credit for the above working code goes to Joseph at jcooney.net

+2  A: 

Are you just looking for "Directory.CreateDirectory(outputDirectory)" where you have your comment? If I add that and run this (minus the process spawning) I get:

Enter Input Directory's full path [eg. c:\vid\]: C:\Users\Dino\ 
In: C:\Users\Dino\ 
Out: C:\Users\Dino\ipod\ 
C:\Users\Dino\x.avi
-i "C:\Users\Dino\x.avi" -t 1 -c 1 -o "C:\Users\Dino\ipod\x.mp4" --preset="iPod"

But I think you really want to either look at the Path class which has Path.Combine which you can use instead of just concatenating the strings.

Dino Viehland
Thanks for replying! I realized that i have a misplaced untabbed Print s.Fullname on my broken script this morning. I thought it was crashing at Directory.CreateDirectory(outputDirectory) thats why I removed it and replaced it with a comment (I have mistakenly though that I had to somehow cast the string into a type that can be used with the Directory class.)
Azeworai