开发者

Check if we have write access to a folder? Delphi [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How can I use Delphi to test if a Directory is writeable?

My program will download an upda开发者_开发技巧te for the user if they request it. The user has to specify the location to save the installer. They might pick a directory which they don't have access to save something to. In this case the download starts (downloading to a temporary directory I assume) and we only know that it failed when it ends and tries to move the file into the folder.

Is there a simple way to check if we have write permissions on a folder in Delhi?


There is AccessCheck function or tricks, but this information is not reliable in generic case.

So, usually you just need to create file to check, if you have access for that.

For your specific case, you have the following choices:

  1. After save dialog closing: try to create a file in target folder with the name of downloading file. Delete it after check. Not pretty, since you rarely may have access to create files, but not to delete them.

  2. After save dialog closing: try to create a file in target folder with the name of downloading file. Keep that handle open and move file content to it after download is complete. Not pretty, since you can't move file, you need to copy it.

  3. (the right one?) Just bring save dialog again on any access denied issues.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜