Delphi 测试磁盘是否具有写访问权限


本文整理自网络,侵删。

 


 function CanWrite(drive: string): boolean;
    var
        OldMode: Cardinal;
    begin
        OldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
        try
            with TStringList.Create do
                try
                    SaveToFile(drive + ':\file.txt');
                    result := true;

                    try
                        deletefile(drive + ':\file.txt');
                    except
                    end;
                except
                    result := false;
                end;
        finally
            SetErrorMode(OldMode);
        end;
end;




调用

 if CanWrite('g') = true then
    begin
        showmessage('可以写');
    end
    else
    begin
        showmessage('不能写');
end;

来源:http://www.xuexidashi.vip/h-nd-1629.html#_np=125_826

相关阅读 >>

Delphi实现变速齿轮

Delphi sql语句查询最新的各个台位的最后一个检测值

Delphi 将整数转换为罗马数字

Delphi 错误no ftp list parsers have been registered

Delphi 让控制台窗口不现实出来

Delphi 释放资源文件

Delphi 动态调用chm文件

Delphi文件操作所涉及的一些函数

Delphi ansiendstext 用法之一(路径结尾自动加\)

如何用Delphi实现windows xp中“本地连接”的启用和禁用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...