Tag: 目录

C#如何知道给定路径是否代表根驱动器?

如何知道给定目录是否为根驱动器? (除了检查其路径是否等于“A:”,“B:”,“C:”等)

如何将文件路径数组转换为分层JSON结构

我正在尝试在给定其所有文件和路径的数组的情况下创建机器目录结构的JSON。 该数组看起来像这样: string[] dirArray = { “./proc/15/task/15/exe”, “./proc/15/task/15/mounts/mounts.xml”, “./proc/15/task/15/mountinfo/mountinfo.xml”, “./proc/15/task/15/clear_refs/clear_ref.xml”, “./proc/14/loginuid/loginuid.xml”, “./proc/14/sessionid/sessionid.xml”, “./proc/14/coredump_filter/coredump_filter.xml”, “./proc/14/io/io.xml” } 我瞄准的目标JSON是这样的: { “.”: { “file”: { “name”:”fileInRoot.xml” }, “proc”: { “file”: { “name”:”fileInProc.xml” }, “15”: { “file”: { “name”:”fileIn15.xml” }, “task”: { “file”: { “name”:”fileInTask.xml” }, “15”: { “file”: { “name”:”fileInTask.xml” }, “mounts”: { “file”: { “name”:”fileInMounts.xml” } }, “mountsInfo”: […]

如何使用C#更改命令提示符中的目录位置?

我通过以下代码使用C#成功打开了命令提示符窗口。 Process p = new Process(); p.StartInfo.FileName = “cmd.exe”; p.StartInfo.WorkingDirectory = @”d:\pdf2xml”; p.StartInfo.WindowStyle = ProcessWindowStyle.Normal; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardInput = true; p.Start(); p.StandardInput.WriteLine(@”pdftoxml.win32.1.2.7 -annotation “+filename); p.StandardInput.WriteLine(@”cd D:\python-source\ds-xmlStudio-1.0-py27″); p.StandardInput.WriteLine(@”main.py -i example-8.xml -o outp.xml”); p.WaitForExit(); 但是,我也通过命令来更改目录。 问题: 如何更改目录位置? Cmd提示将在打开后始终显示… 请指导我摆脱这些问题……

读取C#中目录的权限

我注意到如果您更改特定目录的安全设置,您可以使该文件夹不再在Windows中“浏览”。 特别是,将管理员的“读取”权限更改为“拒绝”将使该文件夹无法访问。 我现在的问题是,我如何在代码中解决这个问题? 我跟着让我接近,但它仍然是不对的: /// /// Takes in a directory and determines if the current user has read access to it (doesn’t work for network drives) /// THIS IS VERY HACKY /// /// directoryInfo object to the directory to examine /// true if read access is available, false otherwise public static bool IsDirectoryReadable(DirectoryInfo dInfo) { […]

* FASTEST *目录列表

我有大量的目录,我想尽快读取所有文件。 我的意思是,快速没有DirectoryInfo.GetFiles,而是“从磁盘低级别获取集群”。 当然,.NET 2.0,c# 类似的问题在这里,但这种方法没有任何好处: C#目录列出海量目录 有人建议在FindFirst / FindNext上使用pInvoke。 有人试过这个并且能够分享结果吗?

如何使用.NET压缩目录?

我有一个包含多个文件的目录。 我想将此文件夹压缩为zip或tar.gz文件。 我怎样才能在C#中完成他的工作?

C#:从目录中获取5个最新(最后修改过的)文件

有没有办法可以使用Array存储目录中5个最后修改过的文件的文件位置? 我目前正在使用以下代码获取最后一个文件: DateTime lastHigh = new DateTime(1900,1,1); string highDir; foreach (string subdir in Directory.GetDirectories(path)){ DirectoryInfo fi1 = new DirectoryInfo(subdir); DateTime created = fi1.LastWriteTime; if (created > lastHigh){ highDir = subdir; lastHigh = created; } } 我将使用Array将多个文件作为附件发送到电子邮件地址。 UPDATE 我目前正在使用以下代码在1分钟后获取最后修改的文件: string myDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), “Test Folder”); var directory = new DirectoryInfo(myDirectory); DateTime from_date = DateTime.Now.AddMinutes(-1); DateTime to_date […]

C#:在您拥有DirectoryInfo的目录中创建新的FileInfo

我只是想知道你什么时候有: var dir = new DirectoryInfo(@”C:\Temp”); 是否有更简单/更清晰的方法将新文件添加到该目录? var file = new FileInfo(Path.Combine(dir.FullName, “file.ext”)); 我想我可能只是做一个扩展方法或其他东西,但好奇如果已经存在的东西在这里看不到……我的意思是DirectoryInfo确实有GetFiles()方法。

检查文件夹是否包含文件

我有程序写入数据库文件夹已满或空。 现在我正在使用 bool hasFiles=false; (Directory.GetFiles(path).Length >0) ? hasFiles=true: hasFiles=false; 但这需要将近一个小时,而我现在无能为力。 有没有最快的方法来检查文件夹是否有任何文件?

如何检索目录中的所有文件名?

如何检索与目录中的模式匹配的所有文件名? 我试过这个,但它返回完整路径而不是文件名。 Directory.GetFiles (path, “*.txt”) 我是否必须手动裁剪结果的目录路径? 它很简单,但也许有一个更简单的解决方案:)