fileinfo

Sorting List<FileInfo> in Natural sorted order .

只愿长相守 提交于 2019-11-28 02:24:40
I have a List which is being returned from a WCF service ,for List of files on Server. Which i am later using to populate the TreeView in my Client Application I need the list to be in naturally sorted order. For ex : I have a list something like List-1 , and my expected result is List-2 but i get List-3 as my output.(refer list given below) List-1 List-2 List-3 abc.jpg abc.jpg abc.jpg abc10.jpg abc10.jpg abc10.jpg abc100.jpg abc97.jpg abc100.jpg abc98.jpg abc98.jpg abc101.jpg abc97.jpg abc100.jpg abc102.jpg abc102.jpg abc101.jpg abc97.jpg abc101.jpg abc102.jpg abc98.jpg So far i have looked

Get all files and directories in specific path fast

孤者浪人 提交于 2019-11-27 10:33:18
I am creating a backup application where c# scans a directory. Before I use to have something like this in order to get all the files and subfiles in a directory: DirectoryInfo di = new DirectoryInfo("A:\\"); var directories= di.GetFiles("*", SearchOption.AllDirectories); foreach (FileInfo d in directories) { //Add files to a list so that later they can be compared to see if each file // needs to be copid or not } The only problem with that is that sometimes a file could not be accessed and I get several errors. an example of an error that I get is: As a result I created a recursive method

.NET FileInfo.LastWriteTime & FileInfo.LastAccessTime are wrong

。_饼干妹妹 提交于 2019-11-27 08:18:23
When I call FileInfo(path).LastAccessTime or FileInfo(path).LastWriteTime on a file that is in the process of being written it returns the time that the file was created, not the last time it was written to (ie. now). Is there a way to get this information? Edit: To all the responses so far. I hadn't tried Refresh() but that does not do it either. I am returned the time that the file was started to be written to. The same goes for the static method, and creating a new instance of FileInfo . Codymanix might have the answer, but I'm not running Windows Server (using Windows 7), and I don't know

Sorting List<FileInfo> in Natural sorted order .

雨燕双飞 提交于 2019-11-27 04:54:56
问题 I have a List which is being returned from a WCF service ,for List of files on Server. Which i am later using to populate the TreeView in my Client Application I need the list to be in naturally sorted order. For ex : I have a list something like List-1 , and my expected result is List-2 but i get List-3 as my output.(refer list given below) List-1 List-2 List-3 abc.jpg abc.jpg abc.jpg abc10.jpg abc10.jpg abc10.jpg abc100.jpg abc97.jpg abc100.jpg abc98.jpg abc98.jpg abc101.jpg abc97.jpg

Get all files and directories in specific path fast

◇◆丶佛笑我妖孽 提交于 2019-11-26 22:19:42
问题 I am creating a backup application where c# scans a directory. Before I use to have something like this in order to get all the files and subfiles in a directory: DirectoryInfo di = new DirectoryInfo("A:\\"); var directories= di.GetFiles("*", SearchOption.AllDirectories); foreach (FileInfo d in directories) { //Add files to a list so that later they can be compared to see if each file // needs to be copid or not } The only problem with that is that sometimes a file could not be accessed and I

.NET FileInfo.LastWriteTime & FileInfo.LastAccessTime are wrong

北城余情 提交于 2019-11-26 14:07:25
问题 When I call FileInfo(path).LastAccessTime or FileInfo(path).LastWriteTime on a file that is in the process of being written it returns the time that the file was created, not the last time it was written to (ie. now). Is there a way to get this information? Edit: To all the responses so far. I hadn't tried Refresh() but that does not do it either. I am returned the time that the file was started to be written to. The same goes for the static method, and creating a new instance of FileInfo .

How to check if a file exists in a folder?

我的梦境 提交于 2019-11-26 12:22:36
问题 I need to check if an xml file exists in the folder. DirectoryInfo di = new DirectoryInfo(ProcessingDirectory); FileInfo[] TXTFiles = di.GetFiles(\"*.xml\"); if (TXTFiles.Length == 0) { log.Info(\"no files present\") } Is this the best way to check a file exists in the folder. I need to check just an xml file is present 回答1: This is a way to see if any XML-files exists in that folder, yes. To check for specific files use File.Exists(path), which will return a boolean indicating wheter the

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) {

Can I show file copy progress using FileInfo.CopyTo() in .NET?

浪子不回头ぞ 提交于 2019-11-26 05:24:50
问题 I\'ve created a copy utility in c# (.NET 2.0 Framework) that copies files, directories and recursive sub directories etc. The program has a GUI that shows the current file being copied, the current file number (sequence), the total number of files to be copied and the percentage completed for the copy operations. There is also a progress bar, that is based on current file / total files. My problem is related to copying large files. I\'ve been unable to find a way to indicate the total copy