我的目标是刷新我在文件夹中保存的文件以显示其上的最后修改日期。因为没有刷新它没有显示hover上的最后修改日期。有没有办法刷新文件夹中的文件使用c#?
任何帮助都会非常感激
答案 0 :(得分: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中,这将刷新整个文件夹,而不仅仅是指定的文件。
答案 1 :(得分:0)
答案 2 :(得分:0)
如果您只想刷新目录视图,可以执行Directory.GetFiles()