命令提示符进程问题 [英] Problem with Command Prompt Process
问题描述
大家好,
我遇到了命令提示过程的问题。它成功运行了cmd
提示,并成功更改了目录,但我不能让
让StartInfo.Arguments正常工作。我的代码如下,
第一个找到最近修改过的文件夹。
DirectoryInfo Direc = new DirectoryInfo(@" U:\ MyyFld \\ \\ _Obober");
DirectoryInfo [] FoldersArr = Direc.GetDirectories();
DateTime MostRecent = FoldersArr [0] .LastWriteTime;
DirectoryInfo MostRecentDir = FoldersArr [0];
for(int i = 1; i< FoldersArr.Length; i ++)
{
if(MostRecent.CompareTo(FoldersArr [i] .LastWriteTime)< 0)
{
MostRecent = FoldersArr [i] .LastWriteTime;
MostRecentDir = FoldersArr [i];
}
}
----- - - - - - - - - - - 处理 - - - - - - - - - - - - - - - ------
流程proc = new流程();
proc.StartInfo.FileName =" cmd";
proc.StartInfo.WorkingDirectory = @ Direc.FullName;
proc.StartInfo.Arguments =" compact / u / s:" +
MostRecentDir.Name;
proc.StartInfo.UseShellExecute = false;
proc.Start();
>
推荐答案
确保目录名用双引号括起来,否则
目录名中的空格(例如c:\ program files \ ...)将导致
问题。
HTH
Ollie Riches
Dyl <莫**************** @ yahoo.com>在消息中写道
news:11 ********************* @ o13g2000cwo.googlegro ups.com ...
make sure that the directory name is enclosed with double quotes otherwise
spaces in the directory name (e.g. c:\program files\...) will cause
problems.
HTH
Ollie Riches
"Dyl" <mo****************@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
大家好,
我遇到了命令提示过程的问题。它成功运行cmd
提示,并成功更改目录,但我不能让StartInfo.Arguments正常工作。我的代码如下,首先找到最近修改过的文件夹。
DirectoryInfo Direc = new DirectoryInfo(@U:\ MyyFld \October);
DirectoryInfo [] FoldersArr = Direc.GetDirectories();
DateTime MostRecent = FoldersArr [0] .LastWriteTime;
DirectoryInfo MostRecentDir = FoldersArr [0];
for(int i = 1; i< FoldersArr.Length; i ++)
{
if(MostRecent.CompareTo(FoldersArr [i] .LastWriteTime)< 0)
{
MostRecent = FoldersArr [i] .LastWriteTime;
MostRecentDir = FoldersArr [i];
}
}
----------- - - - - - - - 处理 - - - - - - - - - - - - - - - - - -
进程proc = new Process();
proc.StartInfo.FileName =" cmd";
proc.StartInfo.WorkingDirectory = @ Direc.FullName;
proc.StartInfo.Arguments =" compact / u / s:" +
MostRecentDir.Name;
proc.StartInfo.UseShellExecute = false;
proc.Start();
Hi all,
I am having a problem with a command prompt process. It runs the cmd
prompt sucessfully, and changes the directory succesfully, but I can''t
get the StartInfo.Arguments to work properly. My code is below, the
first stuff finds the most recently modified folder.
DirectoryInfo Direc = new DirectoryInfo(@"U:\MyFld\October");
DirectoryInfo[] FoldersArr = Direc.GetDirectories();
DateTime MostRecent = FoldersArr[0].LastWriteTime;
DirectoryInfo MostRecentDir = FoldersArr[0];
for (int i = 1; i < FoldersArr.Length; i++)
{
if (MostRecent.CompareTo(FoldersArr[i].LastWriteTime) < 0)
{
MostRecent = FoldersArr[i].LastWriteTime;
MostRecentDir = FoldersArr[i];
}
}
-------------------------Process-----------------------------------
Process proc = new Process();
proc.StartInfo.FileName = "cmd";
proc.StartInfo.WorkingDirectory = @Direc.FullName;
proc.StartInfo.Arguments = "compact /u /s:" +
MostRecentDir.Name;
proc.StartInfo.UseShellExecute = false;
proc.Start();
感谢您的回复Ollie,
但我不知道在我的代码中将双引号放在哪里。你在目录名称周围说了
,但你可以在我的代码中指定一下吗?
Thanks for your reply Ollie,
But I am not sure where to put the double quotes in my code. You said
around the directory name, but could you specify where in my code?
试试这个:
proc.StartInfo.Arguments =" compact / u / s:\"" + MostRecentDir.Name +" \"" ;;
HTH
Ollie Riches
" ; DYL" <莫**************** @ yahoo.com>在消息中写道
news:11 ********************** @ z14g2000cwz.googlegr oups.com ...
try this:
proc.StartInfo.Arguments = "compact /u /s:\"" + MostRecentDir.Name + "\"";
HTH
Ollie Riches
"Dyl" <mo****************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
感谢您的回复Ollie,
但我不知道在我的代码中将双引号放在哪里。你在目录名称周围说了,但你可以在我的代码中指定哪里吗?
Thanks for your reply Ollie,
But I am not sure where to put the double quotes in my code. You said
around the directory name, but could you specify where in my code?
这篇关于命令提示符进程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!