C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\_PRODUKCIJA\D
ebug\DynamicHtmlTool.exe
Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\_PRO
DUKCIJA\Debug\DynamicHtmlTool.exe' or one of its dependencies. An attempt was ma
de to load a program with an incorrect format..
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>
Run Code Online (Sandbox Code Playgroud)
服务是x86编译,即使两台计算机都是x64,它可以在我的计算机上运行.在服务器哪里是win 2008我得到这个错误.
我试试谷歌的解决方案但没有工作.
就像写在这里我有x86项目 http://www.davesquared.net/2008/12/systembadimageformatexception-on-64-bit.html
我需要删除包含只读文件的目录.哪种方法更好:
使用DirectoryInfo.Delete(),或,
ManagementObject.InvokeMethod("Delete")?
有了DirectoryInfo.Delete(),我必须手动关闭每个文件的只读属性,但ManagementObject.InvokeMethod("Delete")似乎不需要.有没有人比另一个人更优先?
示例代码(test.txt是只读的).
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\David\Desktop\");
dir.CreateSubdirectory("Test");
DirectoryInfo test = new DirectoryInfo(@"C:\Users\David\Desktop\Test\");
File.Copy(@"C:\Users\David\Desktop\test.txt", @"C:\Users\David\Desktop\Test\test.txt");
File.SetAttributes(@"C:\Users\David\Desktop\Test\test.txt", FileAttributes.Archive);
test.Delete(true);
Run Code Online (Sandbox Code Playgroud)
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\David\Desktop\");
dir.CreateSubdirectory("Test");
DirectoryInfo test = new DirectoryInfo(@"C:\Users\David\Desktop\Test\");
File.Copy(@"C:\Users\David\Desktop\test.txt", @"C:\Users\David\Desktop\Test\test.txt");
string folder = @"C:\Users\David\Desktop\Test";
string dirObject = "Win32_Directory.Name='" + folder + "'";
using (ManagementObject managementObject = new ManagementObject(dirObject))
{
managementObject.Get();
ManagementBaseObject outParams = managementObject.InvokeMethod("Delete", null,
null);
// ReturnValue should be 0, else failure
if (Convert.ToInt32(outParams.Properties["ReturnValue"].Value) != 0) …Run Code Online (Sandbox Code Playgroud) 如何通过C#中的进程ID获取打开文件句柄列表?
我有兴趣挖掘并获取文件名.
寻找程序化等价的进程资源管理器.
这很可能需要互操作.
考虑到在此上添加赏金,实现是非常复杂的.
在我的应用程序中,我构建了一个用户可以创建图片库的系统.在磁盘上以category_name/gallery_name/{pictures}格式保存在文件夹中的照片.每张上传的照片都存储在上面给出的相关目录结构下.
当尝试删除类别,以及从数据库中删除时,我也想删除系统中的相关文件夹.当我第一次收到错误消息"目录不为空"时,我搜索并找到了这个解决方案:
public static void DeleteDirectory(string target_dir)
{
string[] files = Directory.GetFiles(target_dir);
string[] dirs = Directory.GetDirectories(target_dir);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
Directory.Delete(target_dir, false);
}
Run Code Online (Sandbox Code Playgroud)
使用此解决方案,"gallery_name"文件夹中的照片被删除就好了,然后gallery_name文件夹本身被删除了.所以我们现在留下一个空的category_name文件夹.然后调用上面子例程(Directory.Delete(target_dir, false);)中的最后一部分代码来删除category_name文件夹.错误再次引发..
有谁知道解决这个问题?
Directory.Delete(target_dir, true); 没用,这就是我尝试替代方案的原因.我得到的异常消息是:
System.IO.IOException was unhandled by user code
HResult=-2147024751
Message=The directory is not empty.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String …Run Code Online (Sandbox Code Playgroud) 我有非常奇怪的行为.我有,
Directory.Delete(tempFolder, true);
if (Directory.Exists(tempFolder))
{
}
Run Code Online (Sandbox Code Playgroud)
有时Directory.Exists返回true.为什么?可能是探险家是开放的吗?
应用程序需要在目录中创建文件,在目录中执行某些操作,然后删除该文件.例如,下面的源代码:
File.Create("textfile.txt");
// Do something here
File.Delete("textfile.txt");
Run Code Online (Sandbox Code Playgroud)
如果"某事"是一个只需要很短时间的进程,File.Delete将抛出IOException(另一个进程正在使用该文件).根据另一个SO帖子:无法删除Directory.Delete(path,true)的目录,调用Thread.Sleep(0)应该允许前一个进程完成.然而,即使有
File.Create("textfile.txt");
// Do something here
Thread.Sleep(0);
File.Delete("textfile.txt");
Run Code Online (Sandbox Code Playgroud)
仍然会抛出相同的IOException.
我得到的解决方案是一个while循环,尝试重复删除文件,直到它被删除.但我想知道这是否是一个更好的解决方案.
我正在编写一个工具,允许我通过一个相当大的目录和子目录列表.我想删除一个文件夹,如果它是空的.我可以使用以下代码删除空的文件夹和子文件夹:
string dir = textBox1.Text;
string[] folders = System.IO.Directory.GetDirectories(dir, "*.*", System.IO.SearchOption.AllDirectories);
foreach (var directory in folders)
{
if (System.IO.Directory.GetFiles(directory).Length == 0 && System.IO.Directory.GetDirectories(directory).Length == 0)
{
System.IO.StreamWriter Dfile = new System.IO.StreamWriter(newpath, true);
System.IO.Directory.Delete(directory);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何让代码通过,并在每次删除后检查文件夹,因为一旦删除文件夹,它可以使父文件夹为空,然后应该删除.一旦代码找不到任何空文件夹或子文件夹,它就会退出.
在我的示例中,我试图删除特定文件夹下的文件夹.我的文件夹结构如下...... C:\Export\MyDir1\MyDir2\MyDir3\MyDir4\MyDir5这种结构将随时出现.下次运行我的应用程序时,应检查C:\Export\MyDir1目录并删除(如果存在).我是这样写的
private static string getExportPath(string exportTargetPath, string parentIssue)
{
string exportPath = Path.Combine(exportTargetPath, parentIssue);
if (Directory.Exists(exportPath))
{
string[] files = Directory.GetFiles(exportPath);
string[] dirs = Directory.GetDirectories(exportTargetPath);
File.SetAttributes(exportTargetPath, FileAttributes.Normal);
Directory.Delete(exportTargetPath,false);
}
return exportPath;
}
Run Code Online (Sandbox Code Playgroud)
我检查了这个问题中发布的问题 我试过这个但是无法得到解决方案.根据这个问题的建议答案,当我尝试遍历目录时,它将进入无限循环.我在哪里做错了?任何人都可以帮助我吗?
我想删除一个文件夹,但我可以设法把它弄好吗?
我想删除的文件夹名为ExtractedFiles,它位于名为FormValue的文件夹中.
我可以删除同一FormValue文件夹中的电子表格,但无法删除该文件夹.
我认为问题可能是我没有正确的文件夹文件扩展名
这有效:
if (File.Exists(tempFolderPathAlt + saveas + ".xls"))
{
File.Delete(tempFolderPathAlt + saveas + ".xls");
}
Run Code Online (Sandbox Code Playgroud)
这不起作用:
if (File.Exists(tempFolderPathAlt + "ExtractedFiles"))
{
File.Delete(tempFolderPathAlt + "ExtractedFiles");
}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我文件夹的文件扩展名或如何删除文件夹?
我有这条线:
Directory.Delete(outputfiles, true);
Run Code Online (Sandbox Code Playgroud)
如果我将其设置为true那么它也应该删除子目录和文件.现在我检查了该目录是否为空,因此下次将删除该目录.但在此目录中的异常之前,我有另外4个子目录,其中一个我有一个大约7 Mb大小的zip文件.
System.IO.IOException was unhandled
HResult=-2147024751
Message=The directory is not empty.
Source=mscorlib
StackTrace:
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
at Diagnostic_Tool_Blue_Screen.CreateDirectories.CreateDirectoriesAtConstructor() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\CreateDirectories.cs:line 35
at Diagnostic_Tool_Blue_Screen.Form1..ctor() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Form1.cs:line 125
at Diagnostic_Tool_Blue_Screen.Program.Main() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly …Run Code Online (Sandbox Code Playgroud) 我用C#上的程序复制了一些目录/文件.现在,我想删除主目录.
所以这是基本代码:
dir.Delete(true);
Run Code Online (Sandbox Code Playgroud)
但我认为UnauthorizedAccessException(访问directories.acrodata,这是一个文件,被拒绝).
为什么?我怎么强迫它?