SetLastWriteTimeUtc() public static méthode

public static SetLastWriteTimeUtc ( String path, DateTime lastWriteTimeUtc ) : void
path String
lastWriteTimeUtc DateTime
Résultat void
    /// <summary>
    ///     Sets the file's last write time.
    /// </summary>
    /// <param name="path">The path of the file.</param>
    /// <param name="lastWriteTime">A <see cref="DateTime" /> with the file attribute to set.</param>
    /// <exception cref="ArgumentNullException">
    ///     <paramref name="path" /> is <see langword="null" /> (<see langword="Nothing" /> in Visual Basic).
    /// </exception>
    public void SetLastWriteTime(
        string path,
        DateTime lastWriteTime)
    {
        _ = Requires.NotNullOrWhiteSpace(
            path,
            nameof(path));

        FSFile.SetLastWriteTimeUtc(
            path,
            lastWriteTime);
    }
    /// <summary>
    ///     Asynchronously sets the file's last write time.
    /// </summary>
    /// <param name="path">The path of the file.</param>
    /// <param name="lastWriteTime">A <see cref="DateTime" /> with the file attribute to set.</param>
    /// <param name="cancellationToken">The cancellation token to stop this operation.</param>
    /// <returns>A task representing the current operation.</returns>
    /// <exception cref="ArgumentNullException">
    ///     <paramref name="path" /> is <see langword="null" /> (<see langword="Nothing" /> in Visual Basic).
    /// </exception>
    public Task SetLastWriteTimeAsync(
        string path,
        DateTime lastWriteTime,
        CancellationToken cancellationToken = default)
    {
        _ = Requires.NotNullOrWhiteSpace(
            path,
            nameof(path));

        return(Work.OnThreadPoolAsync(
                   state => FSFile.SetLastWriteTimeUtc(
                       state.Path,
                       state.LastWriteTime),
                   (Path: path, LastWriteTime: lastWriteTime),
                   cancellationToken));
    }
Exemple #3
0
        public static Stream OpenWriter(string file)
        {
            bool   exist = Exists(file);
            Stream _IO   = new Stream(new MSIO.FileStream(file, MSIO.FileMode.OpenOrCreate,
                                                          MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite), canRead: false)
            {
                File = file
            };

            System.DateTime t = System.DateTime.UtcNow;
            if (!exist)
            {
                MSIOF.SetCreationTimeUtc(file, t);
            }
            MSIOF.SetLastWriteTimeUtc(file, t);
            MSIOF.SetLastAccessTimeUtc(file, t); return(_IO);
        }
Exemple #4
0
        public Task SetLastWriteTimeUtcAsync(DriveItem driveItem)
        {
            var driveItemPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified());
                break;

            case DriveItemType.File:
                File.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified());
                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(Task.CompletedTask);
        }
Exemple #5
0
        public async Task <DriveItem> CreateOrUpdateAsync(DriveItem driveItem)
        {
            var fullPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.CreateDirectory(fullPath);
                break;

            case DriveItemType.File:

                Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

                if (driveItem.Content != null)
                {
                    using (var stream = File.OpenWrite(fullPath))
                    {
                        driveItem.Content.Seek(0, SeekOrigin.Begin);
                        driveItem.Content.CopyTo(stream);
                    }
                }
                else
                {
                    await new WebClient().DownloadFileTaskAsync(driveItem.Uri(), fullPath);
                }

                File.SetLastWriteTimeUtc(fullPath, driveItem.FileSystemInfo.LastModifiedDateTime.Value.DateTime);

                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(driveItem);
        }
Exemple #6
0
 public static void SetLastWriteTimeUtc(string path, System.DateTime lastWriteTimeUtc) =>
 MSIOF.SetLastWriteTimeUtc(path, lastWriteTimeUtc);
Exemple #7
0
 public void SetLastWriteTime(DateTimeOffset lastWriteTime)
 => F.SetLastWriteTimeUtc(this.FullName, lastWriteTime.UtcDateTime);
 /// <summary>
 /// Sets the last write time UTC.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="lastWriteTimeUtc">The last write time UTC.</param>
 public override void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
 {
     File.SetLastWriteTimeUtc(path, lastWriteTimeUtc);
 }