public ActionResult Directories()
{
GetFolderInfo folder = new GetFolderInfo();
{
string dir = @"C:\";
foreach (string d in Directory.GetDirectories(dir))
{
List<string> ab = new List<string>();
我这里有个小问题。我想在列表框中列出目录中的文件。当我双击这些文件时,我希望在文本框中显示该文件。
我得到了这个代码,但是双击时我的目录是错误的。
假设我双击battalionAPC.fbi,文本框中显示的目录是C:\Users\Yvonne\Documents\Visual Studio 2010\Projects\ListBoxTest\ListBoxTest\binDebug\battalionAPC.fbi
但是正确的目录应该是: C:\Users\Yvonne\Documents\Visual Studio 2010\Projects\ListBoxTest\ListBoxTest\
所以我试着遍历我硬盘上的每个文件,但当它到达2115(我想)循环时就停止了。我相信这是由于我使用了递归造成的堆栈溢出,但我是C#的新手,真的不知道。这是我的代码,非常感谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
namespace test_data
{
class Program
{
static string drive = Path.GetPathRo
我试图在C#中使用递归函数中的XmlWriter编写XML文件。该文件应该包含给定目录中的每个文件夹以及每个子文件夹和文件。
我在试图在XML文件中写入特殊字符时遇到了一些困难,它总是给我一个错误
我不能使用“&”、“/”、“-”、“.”、“”等字符。
甚至连数字都不起作用。我试图找到类似的问题,但没有解决办法,我试着替换由特殊字符组成的文件夹和/或文件字符串名,并使用"& ;“、"”、"&apos ;“等对它们进行转义。但这也不起作用。它只是给了我一个不能使用'&‘的错误。
using System;
using
我需要将源目录中的文件覆盖到目标目录。每个文件夹的结构都是不同的,所以我尝试用一种通用的方式。问题是,每个文件夹(源和目标)可能有许多子目录,也可能根本没有子目录。
我目前的代码是这样的:
//copy and overwrite the files depending on whatever is in the destination
//search through the destination to find the file
foreach (var dstfile in Directory.GetFiles(targetDir))
{
//search through the
不久前,我不得不编写一个小的C#应用程序来恢复我的硬盘数据(这个问题上的完整上下文)。
为了回答我的问题,我开发了一个控制台应用程序,任务是递归地复制我的HDD的整个文件夹树。
代码可以在下面看到:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CopyCat
{
class Program
我正在尝试使用winforms获取treeview控件中的所有驱动器、文件夹、子文件夹和文件。我看过下面这篇文章。
但这只显示驱动器、文件夹和子文件夹,而不显示这些文件夹中包含的文件。
请任何人帮助并指导我如何在treeview中查看这些文件夹下的所有这些文件,提前谢谢。
编辑:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
usin