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:窗体的扩展样式gwl_exstyle用于setwindowlong

sendmessage这个函数有很多奇妙的用法

Delphi 字符串加单引号

Delphi 只用一条语句就能使tbitmap反色

Delphi tdictionary 泛型如何排序

Delphi 取得当前监视器的分辨率

Delphi dos编程

Delphi 给gmail发送邮件

Delphi 匹配中文的正则表达式

Delphi webbrowser载入自定义html内容并显示

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



打赏

取消

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

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

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

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

评论

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