1

My Delphi application frequently deletes files, etc. and if the user is exploring that directory I want to get it to automatically refresh.

For example, My Computer should automatically refresh.

I have googled but have not found a thing. I have no idea how to do this :/

Cheers for any advice! Adrian

Adrian
  • 323
  • 2
  • 5
  • 17
  • I remember reading on the TortoiseSVN mailing list that refreshing the left hand explorer pane is not possible. The right hand pane can be refreshed from a windows shell extension. I guess you could try finding the window handle and sending an F5 key stroke to it. – Keith Miller Aug 18 '12 at 10:04
  • On Vista and up, the file list view will update. On XP it won't because that's how the XP explorer was designed. You should stick with the default system behaviour. Remember that your app as it stands behaves exactly the same was as explorer does. – David Heffernan Aug 18 '12 at 11:47

2 Answers2

2

Call the SHChangeNotify() function when you delete a file. This will notify the shell, which in turn will notify it's observers such as the Windows File Explorer. TortoiseSVN does it this way (Evidence here).

Also see:

  1. How to refresh Windows Explorer
  2. How can I programmatically refresh Windows Explorer?
Community
  • 1
  • 1
Sean B. Durkin
  • 12,659
  • 1
  • 36
  • 65
  • This is not needed. Try calling DeleteFile and watch the item disappear in your explorer windows. – David Heffernan Aug 18 '12 at 12:07
  • Not tested, but I believe that does not happen in XP and Windows 2000. Therefore the purpose of the SHChangeNotify() is to make it update on the older o/s's as well. – Sean B. Durkin Aug 18 '12 at 12:10
  • I already said that in my comment to the Q. However, I think it would be odd to go against the system default behaviour. I believe it would lead to performance problems since XP explorer enumerates entire folder at once, unlike later OS. Did you even test if this SHChangeNotify has the desired effect on XP. It looks to me like it's designed for something else. – David Heffernan Aug 18 '12 at 13:34
  • 1
    The OP has asked the question, and that is the correct answer. You can have a debate about whether or not he should be even trying to do it in XP, but that would be a side bar, and a fairly weak argument IMHO. – Sean B. Durkin Aug 18 '12 at 14:16
  • That's why I made the point in a comment. But did you test this in XP? Does it work? – David Heffernan Aug 18 '12 at 14:20
  • 1
    i couldn't make out from those links whether or not the update would work for the file list after a deletion. And what params should you pass to that function? I think my points regarding Vista+ are very valid though. Would be crazy to call that function after deleting a file on Vista+. You should edit your answer to say that. And also discuss the performance issues on XP. That's just my opinion though. – David Heffernan Aug 18 '12 at 14:53
0

Also can use TShellChangeNotifier component to handle shell changes .

Mojtaba Tajik
  • 1,725
  • 16
  • 34