I found a hard time with the linux in the follow up. Actually I have to find a directory with a DBN, do not know Whether the file will be .bak or .7z If there are many files in the same file, I would have to meet with extention .7z. If there are several files with the same DBNN and extension .7z then I have to get the file at the last writing. This is what I have so far.
string [] files = directory. Gatefiles (directory, "*. *", Searchoption.tap directory); Foreach (file name in file) {var dbName = "test"; Var extention7 = ".7z"; Var extentionBak = ".bak"; If (fileName.Contains (dbName) & amp; amp; amp; (fileName.Contains (extention7)) fileName.Contains (extentionBak))) {Console.WriteLine (fileName); }}
I will not make a LINQ solution only for this - it will be understood It is very difficult.
Here's what I will do:
string gatedesk file (string folder, string dbnname) {var files = directory.expected files (folder, dbName + "*. *"). Select (x = & gt; new {path = x, extension = path.gate extension (x)}). Where (x = & gt; ex extension == ".7z" || x.extension == ".bak") .oir (); If (files.Length == 0) return tap; If (files.Length == 1) returns the file [0]. Path; Var zippedFiles = files.Where (x => x.Extension == ".7z"). ToArray (); If (zippedFiles.Length == 1) zipfile file [0] will return. Path; Return zippedFiles.OrderByDescending (x = & gt; File.GetLastWriteTime (x.Path)). first (). Path; }
Please note that this does not take into account the case where there is no .7z file, but if multiple .bak files for DB can be this scenario, then you According to this the law must be expanded.
No comments:
Post a Comment