directoryinfo

C# How can I solve limitations when using DirectoryInfo?

安稳与你 提交于 2019-12-12 10:33:06
问题 When I recursive through some folders and files, I encounter this error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directoryname must be less than 248 characters. Here's my function private void ProcessDirectory(DirectoryInfo di) { try { DirectoryInfo[] diArr = di.GetDirectories(); foreach (DirectoryInfo directoryInfo in diArr) { if (StopCheck) return; ProcessDirectory(directoryInfo); } ProcessFile(di); } catch

Concatenate string literals with DirectoryInfo enumeration and adding quotation marks.

风流意气都作罢 提交于 2019-12-11 13:35:52
问题 This seems like such an obscure question, but here it goes: Is there a way to concatenate String Literals with a DirectoryInfo enumeration (which contains a file path) while adding quotations around the file path? Further, how can I prevent backslashes from being doubled when converting a DirectoryInfo enumeration to a string? My situation is as follows: DirectoryInfo filePathDirectory = new DirectoryInfo(filePath); Process a = new Process(); a.StartInfo.FileName = "C:\\Windows\\system32\\lpr

How to EnumerateFiles with all subdirectories with C# DirectoryInfo?

半世苍凉 提交于 2019-12-10 19:47:49
问题 I found this code that gets an array of files out of a DirectoryInfo : FileInfo[] fileInfoArray = di.EnumerateFiles().Where(f => extensions.Contains(f.Extension.ToLower())).ToArray(); But it only searches the direct children of the path of DirectoryInfo . i.e., it does not include grandchildren. I guess I need to add SearchOption.AllDirectories parameter to somewhere, but where? I tried : di.EnumerateFiles(SearchOption.AllDirectories).Where(f => extensions.Contains(f.Extension.ToLower()))

Second path fragment must not be a drive or UNC name - Create Subdirectory Error

核能气质少年 提交于 2019-12-10 12:46:09
问题 I have an exception in the third line ofthis code "Second path fragment must not be a drive or UNC name" DirectoryInfo labdi = new DirectoryInfo(Back.mainfolderpath + @"\news\l"); DirectoryInfo tld = new DirectoryInfo(labdi.FullName + @"\" + NorA.sn.labl[i]); tld = labdi.CreateSubdirectory(labdi.FullName + @"\" + NorA.sn.labl[i] + @"\"); There is no useful way on the web. Thank You.:! 回答1: I ran into this one today and finally tracked it down. The exception is trying to tell you that when a

DirectoryInfo.GetFiles method not returning any files

有些话、适合烂在心里 提交于 2019-12-08 12:03:57
问题 I'm trying to return the .config files that exist in %WINDIR%\System32\inetsrv\config . For this I am using the following code: DirectoryInfo configFolder = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%WINDIR%") + @"\System32\inetsrv\"); FileInfo[] configFiles = configFolder.GetFiles("*.config"); This returns zero objects into configFiles . If I use another folder (say D:\DropBox) is works fine! This code used to work, has something changed?? Also, FileInfo fi = new FileInfo

C# - How to list the files in a sub-directory fast, optimised way

只谈情不闲聊 提交于 2019-12-08 03:59:50
问题 I am trying to list the files in all the sub-directories of a root directory with the below approach. But its taking much time when the number of files are in millions. Is there any better approach of doing this. I am using .NET 3.5 so can't use enumerator :-( ******************* Main ************* DirectoryInfo dir = new DirectoryInfo(path); DirectoryInfo[] subDir = dir.GetDirectories(); foreach (DirectoryInfo di in subDir) //call for each sub directory { PopulateList(di.FullName, false); }

Application Settings + DirectoryInfo/FileInfo

无人久伴 提交于 2019-12-07 18:21:53
问题 I'm still new to C#... I'm building a WPF application and I'm trying to apply some User Application Settings. It's easy to insert standard App Settings (int, double, string, etc). I've even got something like WindowState inserted. I'd like to have a DirectoryInfo and/or FileInfo as savable settings instead of Strings. Selected type: System.IO.File gives an error message "Abstract types are not supported". Which makes sense, since how can you implement an abstract type as a setting. Selected

Sorting files from directoryinfo by date in asp.net

こ雲淡風輕ζ 提交于 2019-12-07 10:37:04
问题 how can I sort (not filter) directoryinfo files by date (oldest to recent) ? I am using asp.net and visual studio 2008 回答1: The same as @DaRKoN_ in vb.net: Module Module1 Sub Main() Dim orderedFiles = New System.IO.DirectoryInfo("c:\\").GetFiles().OrderBy(Function(x) x.CreationTime) For Each f As System.IO.FileInfo In orderedFiles Console.WriteLine(String.Format("{0,-15} {1,12}", f.Name, f.CreationTime.ToString)) Next End Sub End Module 回答2: The GetFiles() method on the DirectoryInfo class

Pass an IO.DirectoryInfo property as a parameter to a function?

▼魔方 西西 提交于 2019-12-06 13:17:20
问题 This function uses the bubble algorithm to sort a list of IO.DirectoryInfo by their Name property. How I can specify in a parameter the property that I will to sort the list? For example: "Drive", "Name", "Name.Length", "Directory.Parent", etc... What I thought like a good idea (maybe is not good, I don't know how much can be improved this) is to pass the parameter as string and then cast the string as...? Here is where I'm lost. Public Shared Function BubbleSort_List(list As List(Of IO

Check if DirectoryInfo.FullName is special folder

允我心安 提交于 2019-12-06 11:54:47
My goal is to check, if DirectoryInfo.FullName is one of the special folders. Here is what I'm doing for this (Check directoryInfo.FullName to each special folder if they are equal): DirectoryInfo directoryInfo = new DirectoryInfo("Directory path"); if (directoryInfo.FullName == Environment.GetFolderPath(Environment.SpecialFolder.Windows) || directoryInfo.FullName == Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles ||) ... ... ) { // directoryInfo is the special folder } But there are many special folders (Cookies, ApplicationData, InternetCache, etc.). Is there any way to do