C# : File

[".0s4*0|collections;datetime-format;file",["F@eDGMX","JCMABEBEKAJAKAMA","OBOCSTUUUUTTUUUUYFGDHDGDHDGDADGDADFOBBCBOOCBEEOBOBWSTTUUUUTTUUUU","rwstyy.",".NET","Array","Dictionary","List","String","2D","Async","Console","DataTable","Dates","DateTime","Enum","File","For","Foreach","Format","IEnumerable","If","IndexOf","Lambda","LINQ","Optimization","Parse","Path","Process","Property","Random","Regex","Replace","Sort","Split","Static","Substring","Switch","Tuple","While","Directory.GetFiles"," returns the file names in a folder. It is found in the System.IO namespace. It returns a string array\u2014this contains the full paths of all the files contained inside the specified directory. ","String Array ","array","Example."," You must include the System.IO namespace with a using directive at the top of your file, or use the fully qualified name System.IO.Directory.GetFiles type. The example program here uses the C:\\ directory. ","Also: ","It filters the files in that directory and only displays the ones with the \"BIN\" extension.","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","br","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","Based on:"," .NET 4.6\n\n","C# program that gets files in directories","\n\nusing System;\nusing System.IO;\n\nclass Program\n{\n static void Main()\n {","\n // Put all file names in root directory into array.\n ","string[] array1 = ","Directory.GetFiles","(@\"C:\\\");","\n\n // Put all bin files in root directory into array.\n // ... This is case-insensitive.\n ","string[] array2 = ","Directory.GetFiles","(@\"C:\\\", \"*.BIN\");","\n\n // Display all files.\n ","Console.WriteLine(","\"--- Files: ---\"",");\n foreach (string name in array1)\n {\n Console.WriteLine(name);\n }","\n\n // Display all BIN files.\n ","Console.WriteLine(","\"--- BIN Files: ---\"",");\n foreach (string name in array2)\n {\n Console.WriteLine(name);\n }\n }\n}\n\n","Output","\n\n--- Files: ---\n (All files in your C:\\ folder)\n--- BIN Files: ---\n (All .bin, .BIN files in your C:\\ folder)","A static method."," You do not need to create a Directory instance to use it. The first parameter to the method is the directory path. In a Windows Forms program, you can use Environment.SpecialFolder and FolderBrowerDialog. ","Environment ","environment","FolderBrowserDialog ","folderbrowserdialog","Note: ","In ASP.NET, you can use Server.MapPath or the Request.PhysicalApplicationPath property.","MapPath ","mappath","Next,"," the second parameter uses the pattern \"*.BIN\". You have seen these patterns in the \"Open File\" dialogs in Windows before. The pattern string is case-insensitive, meaning it will match files ending in \"BIN\", \"Bin\" and \"bin\".","Discussion."," You can get a List collection of the file paths in a directory. To get the List, you will use the same method calls as in the code example. However, you can convert the arrays to Lists with the ToList extension method. ","Tip: ","Include the System.Linq namespace at the top first\u2014it is included by default in new files.","ToList ","tolist","Convert List, Array ","convert-list-array","List ","list","Recursively scan folders."," Often you will need to get the list of files in a certain directory, and then scan all subdirectories in the folder. There are several ways to accomplish this task, including using true recursion. ","Recursive File List ","recursive-file-list","Performance."," Directory.GetFiles is fast when used on small directories with few files. But for large directories, with thousands of files, Directory.EnumerateFiles is faster. A benchmark of these methods is available. ","EnumerateFiles, GetFiles Benchmark ","directory","Summary."," We saw the Directory.GetFiles method, which will return the list of files in a specified directory on your hard drive, using the C# language. We tested the method on the C:\\ root directory, and discussed issues related to its usage. ","br","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","3679700504","data-ad-format","link","br","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto"],"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAAByCAAAAADMwOSzAAACe0lEQVR4Xu3csY7kMAgG4Lz/86Wkp6ZAokDy6RTfodVsTDSaxPy7/uux9a0LZpkEb20YNzNVEWYmItr/hYiYWcS8Tcw2cKv8DTPtoxCzqFfC+wGXgCchYlGvgDfp9MBd/xNsIj7otL8XHwC8x14Sq04/Yine4tRvwEvP6ypqPXp+dgneY+nbaZPwHscOh7eww+HDjoL/uJ1m4D3scPjYFw8fawDxUWjw8LErFP7TB7/z0/jYFA8fB4+Il1iQh47UwF//fvrfLPV/t0WEj+52Ev5yjWc96y/MNNrdR/EX6yRZu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