Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实际上不应该像这样检查File.Exists()。文件系统是不稳定的,当您进行检查和尝试处理文件时,文件很容易消失或权限发生变化。在API提供“TryOpen()”方法之前,最好的方法就是处理异常crashes@lndebi:在哪里?在哪一行,有什么异常?_C#_Exception_Try Catch - Fatal编程技术网

C# 实际上不应该像这样检查File.Exists()。文件系统是不稳定的,当您进行检查和尝试处理文件时,文件很容易消失或权限发生变化。在API提供“TryOpen()”方法之前,最好的方法就是处理异常crashes@lndebi:在哪里?在哪一行,有什么异常?

C# 实际上不应该像这样检查File.Exists()。文件系统是不稳定的,当您进行检查和尝试处理文件时,文件很容易消失或权限发生变化。在API提供“TryOpen()”方法之前,最好的方法就是处理异常crashes@lndebi:在哪里?在哪一行,有什么异常?,c#,exception,try-catch,C#,Exception,Try Catch,实际上不应该像这样检查File.Exists()。文件系统是不稳定的,当您进行检查和尝试处理文件时,文件很容易消失或权限发生变化。在API提供“TryOpen()”方法之前,最好的方法就是处理异常crashes@lndebi:在哪里?在哪一行,有什么异常?它在字符串FullFilePath=Path.Combine(uninstalldirectory,installname)处崩溃@lndebi:打印出所有中间变量,这样您就可以对正在发生的事情有更多的了解。特别是installName(在修改


实际上不应该像这样检查File.Exists()。文件系统是不稳定的,当您进行检查和尝试处理文件时,文件很容易消失或权限发生变化。在API提供“TryOpen()”方法之前,最好的方法就是处理异常crashes@lndebi:在哪里?在哪一行,有什么异常?它在字符串FullFilePath=Path.Combine(uninstalldirectory,installname)处崩溃@lndebi:打印出所有中间变量,这样您就可以对正在发生的事情有更多的了解。特别是installName(在修改之前和之后)和FullFilePath。文件系统是不稳定的,当您进行检查和尝试处理文件时,文件很容易消失或权限发生变化。在API提供“TryOpen()”方法之前,最好的方法就是处理异常。我不想让它执行另一个程序,我正在编写一个跨平台的包管理器(将很快将其移植到mono),这是它删除已安装包的部分。我希望用户能够键入simtho-del“Mozilla Firefox”,它将删除Mozilla Firefox。不要担心它的很多细节,我已经介绍了它的大部分内容,请帮我解决这个问题。坦白说,lndebi,你的代码充满了错误,在它以任何合理的方式工作之前,你需要解决细节。你有什么理由不回答我提出的调试问题吗?你的第二个要点是错误的,因为文件系统是不稳定的,这意味着在检查和尝试使用文件时,文件可能会被删除或权限会发生变化。无论如何,您都必须能够处理异常,因此.Exists()调用只是额外的。@Joel:说得好。要阅读有趣的内容,请查阅MSDN文档中的
文件。Exists
,并浏览指南中从3.0到3.5到4.0的更改。我不想让它执行另一个程序,我正在编写一个跨平台软件包管理器(很快将其移植到mono),这是it删除已安装软件包的部分。我希望用户能够键入simtho-del“Mozilla Firefox”,它将删除Mozilla Firefox。不要担心它的很多细节,我已经介绍了它的大部分内容,请帮我解决这个问题。坦白说,lndebi,你的代码充满了错误,在它以任何合理的方式工作之前,你需要解决细节。你有什么理由不回答我提出的调试问题吗?你的第二个要点是错误的,因为文件系统是不稳定的,这意味着在检查和尝试使用文件时,文件可能会被删除或权限会发生变化。无论如何,您都必须能够处理异常,因此.Exists()调用只是额外的。@Joel:说得好。要阅读有趣的内容,请查阅MSDN文档中的
文件.Exists
,并浏览指南中从3.0到3.5到4.0的更改。
if (startarg.Contains("-del") == true)
            {
                //Searches "Uninstallers" folder for uninstaller containing the name that they type after "-del" and runs it
                string uninstalldirectory = Path.Combine(Directory.GetCurrentDirectory(), "Uninstallers");
                DirectoryInfo UninstallDir = new DirectoryInfo(uninstalldirectory);
                string installname = startarg[2].ToString();
                //Removes file extesion "-del "
                installname.Remove(0, 5);
                string FullFilePath = Path.Combine(uninstalldirectory, installname);
                try
                {
                    //Makes the uninstaller invisible to the user and sets other settings
                    Process Uninstaller = new Process();
                    Uninstaller.StartInfo.FileName = FullFilePath;
                    Uninstaller.StartInfo.UseShellExecute = false;
                    Uninstaller.StartInfo.CreateNoWindow = true;
                    Uninstaller.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    Uninstaller.Start();
                }
                //Only is run if the package isn't installed
                catch (System.Exception)
                {
                    Console.WriteLine("The specified package is not installed, you most likely mispelled it or didnt put quotes around it, try again");
                }

            }
if(File.Exists(FullFilePath))
{
   //uninstall
}
else
{
   Console.WriteLine("The specified package is not installed, you most likely mispelled it or didnt put quotes around it, try again");
}
 //Removes file extesion "-del "
 installname.Remove(0, 5);
installname = installname.Remove(0, 5);
myapp.exe foo bar -del "C:\myfile.txt"
args[0] // foo
args[1] // bar
args[2] // -del
args[3] // C:\myfile.txt