If you would like to iterate multiple items in a directory, you need a DirectoryInfo, not a FileInfo, object. Assuming that you want to get all files in finfo's directory, the code should be like this: foreach (FileInfo filemove in finfo.Directory.EnumerateFiles()) { ... } finfo.Directory gives you DirectoryInfo for finfo's...
You'll want to look into the SkipWhile extension method, the Skip extension method, and then the Take extension method. Additionally, utilize the Directory.EnumerateFiles instead. var files = Directory.EnumerateFiles(pathToFiles, "*.jpg") .Select(x => new FileInfo(x)) .OrderByDescending(x => x.LastWriteTime) .SkipWhile(x => !String.Equals(x.Name, "b.jpg") .Skip(1) .Take(3); Basically, once you have your ordered sequence, skip...
private bool IsValid(string value) { string regexString = "^sr-([a-z0-9]+)-([a-z0-9-]+)-matchresults.xml"; return Regex.IsMatch(value, regexString); } This method will give you the files with the specified format (sr-{first_id}-{second_id}-matchresults.xml). Note: your Ids can contain alphanumeric characters also "-" symbol. if you don't want that symbol in id, then code will look like, string regexString...
I've actually checked the code in Reflector and they both do the exact same thing, i.e: return DateTime.FromFileTimeUtc((long) data.ftLastWriteTimeHigh << 32 | (long) data.ftLastWriteTimeLow); vs return DateTime.FromFileTimeUtc((long) this._data.ftLastWriteTimeHigh << 32 | (long) this._data.ftLastWriteTimeLow); I've also tested it and dates are the same. You must have accidentally compared Utc with a...
You can't. XmlSerializer requires a parameter-less constructor - which FileInfo does not have. It's marked Serializable because there are other serializers that don't have the same requirement. Related question....
r,filesystems,system-calls,fileinfo
Following other's pointers, this should work quite reasonably. Unfortunately it needs root privileges (dued to debugfs) and it's not very efficient yet (especially a bit quick'n dirty on regular expressions, but it's 01:00 o clock in the morning here :) ). BTW, we set up the pager to be cat...
So sourcePath contains the source path and filename. You can easily construct the destination path from that, like so: // Get just the filename of the source file. var filename = Path.GetFileName(sourcePath); // Construct a full path to the destination by combining the destination path and the filename. var fullDestPath...
c#,file-io,io,directory,fileinfo
You can try this solution, synchronize both directories. class Program { class FileCompare : System.Collections.Generic.IEqualityComparer<System.IO.FileInfo> { public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2) { return (f1.Name == f2.Name); } public int GetHashCode(System.IO.FileInfo fi) { string s = fi.Name; return s.GetHashCode(); } } static void Main(string[] args) { string sourcePath = @"C:\Users\Administrator\Desktop\Source";...
Just simple use Where, so code looks like (tested): DirectoryInfo info = new DirectoryInfo(@"C:\tmp"); FileInfo[] files = info.GetFiles() .Where(f=>!(f.FullName.EndsWith("tif"))) .OrderByDescending(p => p.CreationTime) .ToArray(); ...
Because FileInfo.Create opens a stream and you don't close it using(fI.Create()) ; Enclosing the call inside a using statement, also if empty, will ensure that the stream created by the call is closed and disposed...
osx,cocoa,file-management,fileinfo
You can get the document kind as shown in the Finder using code like this: NSURL* url = [NSURL fileURLWithPath:path]; NSString* documentKind; NSError* error; if ([url getResourceValue:&documentKind forKey:NSURLLocalizedTypeDescriptionKey error:&error]) { // use documentKind here } else { /* handle error */ } However, the document kind is not suitable for...
Play with this: var allfiles = Directory.GetFiles(yoursearchparams..); files = new List<FileInfo>(); foreach(string f in projects) files.Add(new FileInfo(f)); var filesSorted = files.OrderByDescending(x=>x.CreationTime); This is descending and using creation date. There is also OrderBy and LastWriteTime. Here is the full example, including: Setting colorDepth, a text and multiple extensions and using a...
c++,qt,file-extension,fileinfo
Just use rename function from 'stdio.h'. char oldname[] ="XXX.alt"; char newname[] ="XXX.exe"; result= rename( oldname , newname ); if ( result == 0 ) puts ( "File successfully renamed" ); else perror( "Error renaming file" ); ...
c#,windows-ce,streamreader,fileinfo,directoryinfo
First, calling CreateDirectory in all cases is a bad idea. It's confusing. Instead, check to see if the directory exists, and if it doesn't then create it and exit the function (because if you created it, you know there's no data). This would have found your error much faster and...
You can add a script component to the pipeline which reads the filename from an input variable and writes the file modified date to an output variable: /// <summary> /// This method is called when this script task executes in the control flow. /// Before returning from this method, set...
Fortunately for you, it is quite simple to parse the MP3 format. You do not need to decode it, just look at the header. The MP3 does not have a single header like most files, instead a single file is split to many frames (packets) with their own headers which...