Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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# 删除所有dll扩展_C# - Fatal编程技术网

C# 删除所有dll扩展

C# 删除所有dll扩展,c#,C#,用20000行代码制作了一个程序。 从完成到出版,我唯一的问题是 我正在尝试删除文件夹中以extension.DLL结尾的所有内容。 或者在应用程序检测到.DLL扩展名时阻止其打开 那个可执行文件 现在,我有了一个有效的代码: private void Form1_Load(object sender, EventArgs e) { string curFile = "FILENAME.dll"; if (File.Exists(curFile)) { t

用20000行代码制作了一个程序。 从完成到出版,我唯一的问题是 我正在尝试删除文件夹中以extension.DLL结尾的所有内容。 或者在应用程序检测到.DLL扩展名时阻止其打开 那个可执行文件

现在,我有了一个有效的代码:

private void Form1_Load(object sender, EventArgs e)
{
    string curFile = "FILENAME.dll";
    if (File.Exists(curFile))
    {
        this.Close();
    }
}
这个代码唯一的问题是文件名。任何人都可以将文件名重命名为除此之外的特定名称,并且仍然可以使用修改过的库来删除我的代码 这也是可行的,因为我不需要指定路径或目录的位置,它会为我指定路径或目录。
我几乎需要阻止任何类型的特定扩展与该可执行文件位于同一路径,而不是看到名称“FILENAME.DLL”just.DLL”。

要获取某个目录中的所有DLL,请使用以下方法:

您可以为当前应用程序目录使用

private void Form1_Load(object sender, EventArgs e)
{
    var allDlls = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*.dll");
    if (allDlls.Any())
    {
        this.Close();
    }
}

那不是我想要的。(“指向某个目录的路径,“*.dll”);无法工作,因为其他人没有相同的指定路径。这是published@CrazyLeak
Directory.GetCurrentDirectory
?不,如果执行var allDlls=Directory.EnumerateFiles(Directory.GetCurrentDirectory,.dll)),则该选项无效;或者var allDlls=Directory.GetCurrentDirectory(“路径到某个目录”,“.dll”);我犯了一个错误syntax@CrazyLeak我真的不明白你到底想干什么want@CrazyLeak因为Directory.GetCurrentDirectory是一个方法:)
Directory.GetCurrentDirectory()