如何将 raw_input() 转换为目录?

发布于 2024-09-06 02:17:18 字数 1341 浏览 1 评论 0原文

我刚刚拿起 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪#恶を代价 2024-09-13 02:17:18

您是否只是在寻找“Directory.CreateDirectory(outputDirectory)”,您可以在其中发表评论?如果我添加它并运行它(减去进程生成),我会得到:

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"

但我认为您确实想要查看具有 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文