我一直在尝试将python代码转换为c代码。出于某种原因,c代码到达DirectoryInfo声明并表示找不到路径。如果有人能告诉我原因,我将不胜感激。你知道吗
这是原始的python代码:
def encode(path, dest):
for root_dir, dirs, files in os.walk(path, topdown=False):
for name in files:
(base, ext)=os.path.splitext(name)
input_file = os.path.join(root_dir,name)
output_file = os.path.join(dest_dir, base+".mkv")
if (os.path.exists(output_file)):
print ("skipped")
else:
subprocess.call( ["HandBrakeCLI.exe", "-i", input_file, "-o", output_file, "-e", "x264", "--aencoder", "ac3", "-s", "1", "--subtitle-default", "1" ])
这是我目前的c代码:
string qpath = Path.GetFullPath((Environment.CurrentDirectory + "\\Queue\\"));
if (Directory.Exists(Path.GetFullPath(qpath)))
{
var DirMKV = (Directory.GetFiles(qpath, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".mkv") || s.EndsWith(".mp4")).ToArray());
foreach (string file in DirMKV)
{
DirectoryInfo dirinfo = new DirectoryInfo(file);
if (dirinfo.Parent.Parent.ToString().Contains("S"))
{
string ipath = Environment.CurrentDirectory;
string dpath = ipath + @"\Queue\" + dirinfo.Parent.Parent.ToString() + @"\" + Path.GetFileName(file);
string opath = ipath + @"\Finished\" + dirinfo.Parent.Parent.ToString() + @"\" + Path.GetFileName(file);
string arg = "-i " +dpath + " -o " +opath +" -e x264 "+ " --aencoder ac3 "+ "-s 1 "+ "--subtitle-default 1";
if (!File.Exists(opath))
{
Process.Start(ipath + @"\handbrakeCLI.exe", arg);
}
}
}
}
我不懂Python,但据我所见,你的c代码和Python代码做的事情肯定不同。有很多事情还不清楚。我已经用我的建议注释了你的代码。希望这能解决你的问题
对下面的代码发表了评论
下面的代码基于我对您想要什么的猜测
相关问题 更多 >
编程相关推荐