NAnt.Core.Types.FileSet.FindMoreRecentLastWriteTime C# (CSharp) Method

FindMoreRecentLastWriteTime() public static method

Determines if one of the given files has a more recent last write time than the given time. If one of the given files no longer exists, the target will be considered out-of-date.
public static FindMoreRecentLastWriteTime ( StringCollection fileNames, System.DateTime targetLastWriteTime ) : string
fileNames System.Collections.Specialized.StringCollection A collection of filenames to check the last write time against.
targetLastWriteTime System.DateTime The datetime to compare against.
return string
        public static string FindMoreRecentLastWriteTime(StringCollection fileNames, DateTime targetLastWriteTime)
        {
            foreach (string fileName in fileNames) {
                // only check fully file names that have a full path
                if (Path.IsPathRooted(fileName)) {
                    FileInfo fileInfo = new FileInfo(fileName);
                    if (!fileInfo.Exists) {
                        logger.Info(string.Format(CultureInfo.InvariantCulture, "File '{0}' no longer exist (so the target might need to be updated)", fileName, targetLastWriteTime));
                        return fileName;
                    }
                    if (fileInfo.LastWriteTime > targetLastWriteTime) {
                        logger.Info(string.Format(CultureInfo.InvariantCulture, "'{0}' was newer than {1}", fileName, targetLastWriteTime));
                        return fileName;
                    }
                }
            }
            return null;
        }

Same methods

FileSet::FindMoreRecentLastWriteTime ( string fileName, System.DateTime targetLastWriteTime ) : string

Usage Example

Example #1
0
        /// <summary>
        /// Determines if a file has a more recent last write time than the
        /// given time, or no longer exists.
        /// </summary>
        /// <param name="fileName">A file to check the last write time against.</param>
        /// <param name="targetLastWriteTime">The datetime to compare against.</param>
        /// <returns>
        /// The name of the file that has a last write time greater than
        /// <paramref name="targetLastWriteTime" /> or that no longer exists;
        /// otherwise, <see langword="null" />.
        /// </returns>
        public static string FindMoreRecentLastWriteTime(string fileName, DateTime targetLastWriteTime)
        {
            StringCollection fileNames = new StringCollection();

            fileNames.Add(fileName);
            return(FileSet.FindMoreRecentLastWriteTime(fileNames, targetLastWriteTime));
        }