zoukankan      html  css  js  c++  java
  • 用DirectoryExists和FileExists判断指定路径下是否存在指定的文件夹或文件

    1、现在自己要校验的位置建立文件和文件夹。

    2、拖个按钮出来,并双击写入一下代码。

    procedure TForm1.btn_copyClick(Sender: TObject);
    var
      ZkyStrAddDirectory:string;//定义一个字符串,可以用来放文件所在的地址
      ZkyStrAddFile:string;//定义一个字符串,可以用来放文件坐在的地址
    begin
      ZkyStrAddDirectory:=GetCurrentDir+'	est';//将字符串指定为 在程序exe所在目录下test文件夹的路径
      ZkyStrAddFile:=GetCurrentDir+'	est	est_1.txt';//将字符串指定为 在程序exe所在目录下test文件夹内test_1.txt文件的路径
     
      //-------------------------------------------------
      //DirectoryExists('<路径>');
      //该语句只能用于判断文件夹是否存在,不能用于判断文件是否存在。
      //-------------------------------------------------
      if not DirectoryExists('D:	est') then
      begin
        ShowMessage('不存在!D盘不存在test文件夹');//如果该文件夹不存在,则提示不存在
      end
      else
      begin
        ShowMessage('存在!D盘存在test文件夹');
      end;
     
      if DirectoryExists(PChar(ZkyStrAddDirectory)) then
      begin
        ShowMessage('存在!exe所在目录下有test文件夹');//如果该文件夹存在,则提示存在
      end
      else
      begin
        ShowMessage('不存在!exe所在目录下没有test文件夹');
      end;
     
      //-------------------------------------------------
      //FileExists('<路径>');
      //该语句只能用于判断文件是否存在,不能用于判断文件夹是否存在。
      //-------------------------------------------------
      if FileExists('D:	est.txt') then
      begin
        ShowMessage('存在!D盘下有test.txt文件');//如果该文件存在,则提示存在
      end
      else
      begin
        ShowMessage('不存在!D盘不存在test.txt文件');
      end;
     
      if not FileExists(PChar(ZkyStrAddFile)) then
      begin
        ShowMessage('不存在!exe所在目录下的test文件夹内没有test.txt文件');//如果该文件不存在,则提示不存在
      end
      else
      begin
        ShowMessage('存在!exe所在目录下的test文件夹内有test.txt文件');//如果该文件夹存在,则提示存在
      end;
      end;

    运行后,指定路径下的指定文件或文件夹存在,则提示存在,反之提示不存在。 

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    ionic app打包和签名
    js时间戳与日期格式的相互转换
    js获取选中日期的当周的周一和周日
    Error occurred during initialization of VM Could not reserve enough space for 2097152KB object heap
    CSS媒体查询 @media
    [ng:areq] Argument 'XXXXCtrl' is not a function, got undefined
    plsql如何导出查询结果
    angularjs的$http请求方式
    JQuery请求数据的方式
    后台返回xml格式转json
  • 原文地址:https://www.cnblogs.com/jijm123/p/14385578.html
Copyright © 2011-2022 走看看