0

我的目标是刷新我保存在文件夹中的文件以显示最后修改日期。因为不刷新它不会在悬停时显示最后修改日期。那么有没有办法使用 c# 刷新文件夹中的文件?

任何帮助将不胜感激

4

3 回答 3

1

您可以使用该SHChangeNotify功能告诉资源管理器文件已更改。

    public void NotifyItemChanged(string fullPath)
    {
        NativeMethods.SHChangeNotify(
            SHChangeNotifyEvents.UpdateItem,
            SHChangeNotifyFlags.PathW | SHChangeNotifyFlags.NotifyRecursive,
            fullPath,
            null);
    }

    [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
    public static extern void SHChangeNotify(SHChangeNotifyEvents eventID, SHChangeNotifyFlags flags, string path, string path2);

[Flags]
public enum SHChangeNotifyEvents : uint
{
    RenameItem = 0x00000001,
    Create = 0x00000002,
    Delete = 0x00000004,
    MkDir = 0x00000008,
    RmDir = 0x00000010,
    MediaInserted = 0x00000020,
    MediaRemoved = 0x00000040,
    DriveRemoved = 0x00000080,
    DriveAdd = 0x00000100,
    NetShare = 0x00000200,
    NetUnshare = 0x00000400,
    Attributes = 0x00000800,
    UpdateDir = 0x00001000,
    UpdateItem = 0x00002000,
    ServerDisconnect = 0x00004000,
    UpdateImage = 0x00008000,
    DriveAddGui = 0x00010000,
    RenameFolder = 0x00020000,
    FreeSpace = 0x00040000,
    ExtendedEvent = 0x04000000,
    AssocChanged = 0x08000000,
    DiskEvents = 0x0002381F,
    GlobalEvents = 0x0C0581E0,
    AllEvents = 0x7FFFFFFF,
    Interrupt = 0x80000000
}

public enum SHChangeNotifyFlags : uint
{
    IdList = 0x0000,
    PathA = 0x0001,
    PrinterA = 0x0002,
    Dword = 0x0003,
    PathW = 0x0005,
    PrinterW = 0x0006,
    Type = 0x00FF,
    Flush = 0x1000,
    FlushNoWait = 0x3000,
    NotifyRecursive = 0x10000
}

注意:在 Windows XP 中,这将刷新整个文件夹,而不仅仅是指定的文件。

于 2013-10-31T10:14:13.773 回答
0

您可以使用

FileInfo.LastWriteTime

每次循环t

MSDN

于 2013-10-31T10:06:02.167 回答
0

如果您只是想刷新您的目录视图,您可以这样做Directory.GetFiles()

于 2013-10-31T10:07:09.503 回答