我遇到了“系统无法找到指定文件”的问题。在C#.net中 [英] I'm having an issue with "The System cannot find the file specified" in C#.net

查看:96
本文介绍了我遇到了“系统无法找到指定文件”的问题。在C#.net中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码失败的部分:

Here is the part of my code that fails:

private void button1_Click(object sender, EventArgs e)
        {
            string text1 = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";

            Process.Start(("cmd /c" + ("ren " + (textBox1.Text + (" "+ (textBox2.Text + text1))))));
              Process.Start(("cmd /c" + ("attrib +s +h "+ (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\*.*" + " /S /D")))));
              Process.Start(("cmd /c" + ("attrib +s +h " + (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + " /S /D")))));

                
            //Shell(("cmd /c" + ("ren "+ (textBox1.Text + (" "+ (textBox2.Text + text1))))));
            //Shell(("cmd /c" + ("attrib +s +h " + (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\*.*" + " /S /D")))));
            //Shell(("cmd /c" + ("attrib +s +h " + (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + " /S /D")))));
        
}

推荐答案

您的第一个错误是使用CMD.EXE。这根本没有意义。我甚至可以解释原因吗?它什么都不做。您只需将一些命令传递给它即可直接执行。因此,删除CMD / C,再也不要这样做。相反,使用调用

Your first mistake is using CMD.EXE. It makes no sense at all. Do I even explain why? It does nothing. You simply pass some command to it which you can perform directly. Therefore, remove "CMD /C" and never do it again. Instead, use the call
System.Windows.Process.Start("attrib", commandLine);



其中 commandLine 是你的字符串的其余部分,命令行attrib。



然后,连接字符串操作数的括号没有任何意义,完全是多余的。然后,没有硬编码文件名可能有用的情况,但我们假设这只是初步实验,你稍后会删除它。



还有什么。啊,文件名。你根本就没有这些文件。就如此容易。使用CMD.EXE(例如)重现所有操作,不使用您的程序和/ C,然后以编程方式重复所有操作。它应该是相同的。



现在,让我告诉你attrib对文件属性进行操作,这些属性在现代文件系统中几乎变得无关紧要。所以,无论你对他们做什么,都可能只是浪费时间。您正在尝试隐藏文件和系统。任何程序(包括文件管理器)都可以忽略这两个属性(可选地和常规地)。

另一方面,您仍然可以使用它们。例如,您可以在某些多遍处理中临时标记具有某些属性的文件,但我也不会这样做。如果您解释了活动的最终目的,我们可以讨论可能的解决方案。



-SA


where commandLine is the rest of your string, the command line to "attrib".

Then, the brackets around concatenating string operands make no sense, totally superfluous. Then, there are not cases when hard-coded file names can be useful, but let's assume this is just preliminary experiments and you will later remove it.

What else. Ah, file names. You simply don't have these files. As simple as that. Reproduce all operation using CMD.EXE (for example), without your program and "/C", and then repeat it all programmatically. It should to the same.

Now, let me tell you that "attrib" operates on the file attributes which have become practically insignificant in the modern file systems. So, whatever you are doing to them may be just a waste of time. You are trying to make file hidden and system. Both attributes, optionally and routinely, can be ignored by any program, including file managers.
From the other hand, you still can use them. For example, you could temporarily mark files with some attributes in some multi-pass processing, but I would not do it either. If you explain the ultimate purpose of your activity, we can discuss possible solutions.

—SA


这篇关于我遇到了“系统无法找到指定文件”的问题。在C#.net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆