getfiles

Retrieving files from directory that contains large amount of files

♀尐吖头ヾ 提交于 2019-11-27 03:27:13
I have directory that contains nearly 14,000,000 audio samples in *.wav format. All plain storage, no subdirectories. I want to loop through the files, but when I use DirectoryInfo.GetFiles() on that folder the whole application freezes for minutes! Can this be done another way? Perhaps read 1000, process them, then take next 1000 and so on? Haris Hasan Have you tried EnumerateFiles method of DirectoryInfo class? As MSDN Says The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles , you can start enumerating the collection of FileInfo objects before the whole

Directory.GetFiles: how to get only filename, not full path? [duplicate]

谁说胖子不能爱 提交于 2019-11-27 00:49:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to get only filenames within a directory using c#? Using C#, I want to get the list of files in a folder. My goal: ["file1.txt", "file2.txt"] So I wrote this: string[] files = Directory.GetFiles(dir); Unfortunately, I get this output: ["C:\\dir\\file1.txt", "C:\\dir\\file2.txt"] I could strip the unwanted "C:\dir\" part afterward, but is there a more elegant solution? 回答1: You can use System.IO.Path

Sorting the result of Directory.GetFiles in C#

。_饼干妹妹 提交于 2019-11-26 23:00:43
问题 I have this code to list all the files in a directory. class GetTypesProfiler { static List<Data> Test() { List<Data> dataList = new List<Data>(); string folder = @"DIRECTORY"; Console.Write("------------------------------------------\n"); var files = Directory.GetFiles(folder, "*.dll"); Stopwatch sw; foreach (var file in files) { string fileName = Path.GetFileName(file); var fileinfo = new FileInfo(file); long fileSize = fileinfo.Length; Console.WriteLine("{0}/{1}", fileName, fileSize); }

Directory.GetFiles of certain extension

旧巷老猫 提交于 2019-11-26 22:03:36
Is there a way to simplify this linq expression, or is there a better way of doing this? Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || ...); Basically I want to return all files of a certain extension. Unfortunately, this method isn't very flexible. I'd rather be able to add extensions to a list and have Directory.GetFiles return those extensions. Is that possible? dasblinkenlight If you would

GetFiles with multiple extensions [duplicate]

青春壹個敷衍的年華 提交于 2019-11-26 12:22:35
Possible Duplicate: Can you call Directory.GetFiles() with multiple filters? How do you filter on more than one extension? I've tried: FileInfo[] Files = dinfo.GetFiles("*.jpg;*.tiff;*.bmp"); FileInfo[] Files = dinfo.GetFiles("*.jpg,*.tiff,*.bmp"); Cheng Chen Why not create an extension method? That's more readable. public static IEnumerable<FileInfo> GetFilesByExtensions(this DirectoryInfo dir, params string[] extensions) { if (extensions == null) throw new ArgumentNullException("extensions"); IEnumerable<FileInfo> files = Enumerable.Empty<FileInfo>(); foreach(string ext in extensions) {

UnauthorizedAccessException cannot resolve Directory.GetFiles failure [duplicate]

寵の児 提交于 2019-11-26 01:46:01
问题 This question already has answers here : Ignore folders/files when Directory.GetFiles() is denied access (8 answers) Closed 3 years ago . Directory.GetFiles method fails on the first encounter with a folder it has no access rights to. The method throws an UnauthorizedAccessException (which can be caught) but by the time this is done, the method has already failed/terminated. The code I am using is listed below: try { // looks in stated directory and returns the path of all files found

Ignore folders/files when Directory.GetFiles() is denied access

 ̄綄美尐妖づ 提交于 2019-11-26 01:22:22
问题 I am trying to display a list of all files found in the selected directory (and optionally any subdirectories). The problem I am having is that when the GetFiles() method comes across a folder that it cannot access, it throws an exception and the process stops. How do I ignore this exception (and ignore the protected folder/file) and continue adding accessible files to the list? try { if (cbSubFolders.Checked == false) { string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);

UnauthorizedAccessException cannot resolve Directory.GetFiles failure [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-11-25 19:57:32
This question already has an answer here: Ignore folders/files when Directory.GetFiles() is denied access 8 answers Directory.GetFiles method fails on the first encounter with a folder it has no access rights to. The method throws an UnauthorizedAccessException (which can be caught) but by the time this is done, the method has already failed/terminated. The code I am using is listed below: try { // looks in stated directory and returns the path of all files found getFiles = Directory.GetFiles( @directoryToSearch, filetype, SearchOption.AllDirectories); } catch (UnauthorizedAccessException) { }