如何将 raw_input() 转换为目录?
我刚刚拿起 IronPython,并且一直在尝试运行此 IronPython 脚本,但我一直试图从 raw_input 获取 Path 输入作为目录路径。第一个代码块是我正在处理的损坏的代码块。
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()
以下代码块是我目前正在工作的代码块。
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:上述工作代码归功于 jcooney.net 的 Joseph
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否只是在寻找“Directory.CreateDirectory(outputDirectory)”,您可以在其中发表评论?如果我添加它并运行它(减去进程生成),我会得到:
但我认为您确实想要查看具有 Path.Combine 的 Path 类,您可以使用它,而不仅仅是连接字符串。
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:
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.