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 fdquery 验证登录

Delphi 检测文件是否被占用

Delphi 获取标题栏高

Delphi memo1 统计行 列

Delphi opendialog1文件过滤类型

Delphi下程序内存泄露报告

Delphi 实现执行外部程序,并等待程序结束的函数

Delphi thttpclient 时获取跳转后的 url

Delphi tfont类型和json互相转换的函数

Delphi mediaplayer1 播放avi 视频

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



打赏

取消

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

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

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

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

评论

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