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 破解access密码

Delphi中判断窗体最大化和最小化事件

Delphi 使用 {$include} 或 {$i} 指令管理和调用自定义函数

Delphi判断字符串是否包含限制以外的字符 否则置空

Delphi分享pos函数。(比fastpos还要快)

Delphi shellexecute 打开文件夹

Delphi ini文件操作 tinifile、tmeminifile

Delphi中for in 语法应用实例

Delphi与sql server存储过程编程详解

Delphi createdir 建立文件夹路径

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



打赏

取消

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

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

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

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

评论

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