getfiles

What happens with Directory.EnumerateFiles if directory content changes during iteration?

限于喜欢 提交于 2019-11-29 11:35:00
I've read discussions about difference between Directory.EnumerateFiles and Directory.GetFiles(). I understand that internally they both use System.IO.FileSystemEnumerableFactory.CreateFileNameIterator() The difference is that EnumerateFiles might use deferred execution (lazy), while GetFiles() does a ToArray, so the function is already executed. But what happens if files and folders are added to the dictionary during the iteration. Will the iteration only iterate over the items that were present during the EnumerateFiles()? Even worse: what happens if files are removed during iterations: will

Listing Folders in a Directory using asp.net and C#

自作多情 提交于 2019-11-28 12:36:43
.aspx file: <%@ Import Namespace="System.IO" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Explorer</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html> .CS file: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class view2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string path = "~/"; GetFilesFromDirectory(path); } private static void GetFilesFromDirectory(string DirPath)

Exact file extension match with GetFiles()?

只谈情不闲聊 提交于 2019-11-28 12:22:22
I'd like to retrieve a list of files whose extensions match a specified string exactly. DirectoryInfo di = new DirectoryInfo(someValidPath); List<FileInfo> myFiles = new List<FileInfo>(); foreach (FileInfo fi in di.GetFiles("*.txt")) { myFiles.Add(fi); } I get the files with extension *.txt but I also get files with the extension *.txtx , so what I've coded amounts to getting the files whose extension starts with txt . This isn't what I want. Do I need to grab all of the filenames and do a regular expression match to "\\.txt$" (I think), or test each filename string with .EndsWith(".txt") ,

How can I access the “Documents and Settings” folder?

大兔子大兔子 提交于 2019-11-28 12:21:07
I'm using C# .NET 4 with VS 2010. When Iterating over some paths, I'm running this line: files = Directory.GetFiles(path, searchPattern); I get an exception when the path is the documents and settings folder. How can I access it? And no, I don't want to skip the folder with a try and catch. I want to be able to access it somehow. Edit: I got a follow up question. As I told you, I'm iterating over the paths. Is there a way to use Environment.GetFolderPath but somehow idetifying the correct speical folder according to the path I'm currently checking? Saravanan You have to use like this var

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

北战南征 提交于 2019-11-28 06:08:19
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? You can use System.IO.Path.GetFileName to do this. E.g., string[] files = Directory.GetFiles(dir); foreach(string file in files) Console.WriteLine(Path.GetFileName(file)); While you could use FileInfo , it

What happens with Directory.EnumerateFiles if directory content changes during iteration?

偶尔善良 提交于 2019-11-28 04:40:44
问题 I've read discussions about difference between Directory.EnumerateFiles and Directory.GetFiles(). I understand that internally they both use System.IO.FileSystemEnumerableFactory.CreateFileNameIterator() The difference is that EnumerateFiles might use deferred execution (lazy), while GetFiles() does a ToArray, so the function is already executed. But what happens if files and folders are added to the dictionary during the iteration. Will the iteration only iterate over the items that were

Get all files recursively in directories NodejS

此生再无相见时 提交于 2019-11-28 03:01:36
问题 I have a little problem with my function. I would like to get all files in many directories. Currently, I can retrieve the files in the file passed in parameters. I would like to retrieve the html files of each folder in the folder passed as a parameter. I will explain if I put in parameter "test" I retrieve the files in "test" but I would like to retrieve "test / 1 / *. Html", "test / 2 / . / .html ": var srcpath2 = path.join('.', 'diapo', result); function getDirectories(srcpath2) { return

Sorting the result of Directory.GetFiles in C#

微笑、不失礼 提交于 2019-11-27 21:04:48
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); } return dataList; } static void Main() { ... } } I need to print out the file info based on file size or

Listing Folders in a Directory using asp.net and C#

时间秒杀一切 提交于 2019-11-27 07:10:23
问题 .aspx file: <%@ Import Namespace="System.IO" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Explorer</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html> .CS file: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class view2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {

Exact file extension match with GetFiles()?

淺唱寂寞╮ 提交于 2019-11-27 06:59:16
问题 I'd like to retrieve a list of files whose extensions match a specified string exactly. DirectoryInfo di = new DirectoryInfo(someValidPath); List<FileInfo> myFiles = new List<FileInfo>(); foreach (FileInfo fi in di.GetFiles("*.txt")) { myFiles.Add(fi); } I get the files with extension *.txt but I also get files with the extension *.txtx , so what I've coded amounts to getting the files whose extension starts with txt . This isn't what I want. Do I need to grab all of the filenames and do a