Update free space amount displayed in Windows Explorer

天涯浪子 提交于 2019-12-08 04:14:25

问题


how to update free space amount displayed in Windows Explorer for a drive ?

Suppose Windows Explorer is opened and some files are deleted programmatically. Windows Explorer will not be refreshed to show the new free space available.

So, I tried to use SHChangeNotify like this (Delphi code) :

ws := 'C:\';
SHChangeNotify (SHCNE_FREESPACE, SHCNF_PATH, PWideChar(ws), nil); 

but it doesn't update values reported in "Windows Explorer".

Please help.


回答1:


If you are using Delphi 7, then SHCNF_PATH will map to the ANSI version, SHCNF_PATHA. In which case passing PWideChar is wrong. Write it like this:

var
  Drive: string;
....
Drive := 'C:\';
SHChangeNotify(SHCNE_FREESPACE, SHCNF_PATH, PChar(Drive), nil);

Or, if you prefer to use the Unicode version, then you need to use SHCNF_PATHW.

var
  Drive: WideString;
....
Drive := 'C:\';
SHChangeNotify(SHCNE_FREESPACE, SHCNF_PATHW, PWideChar(Drive), nil);


来源:https://stackoverflow.com/questions/13929923/update-free-space-amount-displayed-in-windows-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!