• 路径操作


    本文转自万一老师博客.

    http://www.cnblogs.com/del/archive/2007/12/11/990797.html

    ----------------------------------------------------------------------

    uses
      HTTPApp, Masks;

    procedure TForm1.Button1Click(Sender: TObject);
    var
      ss,s: string;
    begin

      //取DLL所在目录  F:\自做项目\XXX\MsgInjectTest\Release\Msgdll.dll

      szMsgDllPath := GetModuleName(GetModuleHandle('MsgDll.dll'));


      //先提取一个文件名的字符串
      ss := Application.ExeName;
      ShowMessage(ss); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects\Project1.exe 

      //路径
      s := ExtractFilePath(ss);
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects\

      //所在文件夹
      s := ExtractFileDir(ss);
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects

      //所在逻辑盘
      s := ExtractFileDrive(ss);
      ShowMessage(s); //C:

      //文件名
      s := ExtractFileName(ss);
      ShowMessage(s); //Project1.exe

      //文件扩展名
      s := ExtractFileExt(ss);
      ShowMessage(s); //.exe

      //相对路径
      s := ExtractRelativePath('C:\Documents and Settings\wy\My Documents\',ss);
      ShowMessage(s); //RAD Studio\Projects\Project1.exe

      //dos下的短文件名
      s := ExtractShortPathName(ss);
      ShowMessage(s); //C:\DOCUME~1\wy\MYDOCU~1\RADSTU~1\Projects\Project1.exe

      //转换到Unix路径格式, 需要 uses HTTPApp
      s := DosPathToUnixPath(ss);
      ShowMessage(s); //C:/Documents and Settings/wy/My Documents/RAD Studio/Projects/Project1.exe

      //转Unix路径格式为Window格式, 是 DosPathToUnixPath 的逆操作
      s := ExpandUNCFileName(DosPathToUnixPath(ss));
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects\Project1.exe

      //去掉结尾的路径分隔符
      s := ExcludeTrailingPathDelimiter(ExtractFilePath(ss));
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects

      //去掉结尾的路径分隔符, 只是调用:ExcludeTrailingPathDelimiter
      s := ExcludeTrailingBackslash(ExtractFilePath(ss));
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects

      //更换扩展名, 并不修改文件, 只是替换字符串:
      s := ChangeFileExt(ss,'.bak');
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects\Project1.bak

      //更换文件路径:
      s := ChangeFilePath(ss,'c:\temp');
      ShowMessage(s); //c:\temp\Project1.exe

      //判断第几个字符是否是路径分隔符:
      IsPathDelimiter(ss,3); //返回 True

      //判断后缀名是不是 exe; 需要 uses Masks
      MatchesMask(ss,'*.exe'); //返回 True
    end;
    --------------------------------------------------------------------------------

    //分解 ProcessPath (需要 uses FileCtrl)
    var
      s,p,f: string;
      d: Char;
    begin
      s := ParamStr(0);
      ShowMessage(s); //C:\Documents and Settings\wy\My Documents\RAD Studio\Projects\Project1.exe
      ProcessPath(s,d,p,f);
      ShowMessage(d); //C
      ShowMessage(p); //\Documents and Settings\wy\My Documents\RAD Studio\Projects
      ShowMessage(f); //Project1.exe
    end;
    --------------------------------------------------------------------------------

    //压缩显示 MinimizeName (需要 uses FileCtrl)
    var
      s: string;
    begin
      s := ParamStr(0);
      s := MinimizeName(s,Self.Canvas,100);
      ShowMessage(s); //C:\...\Project1.exe
    end;

  • 相关阅读:
    简练软考知识点整理-四控三管一协调
    软考如何刷题
    简练软考知识点整理-瀑螺原迭敏V
    简练软考知识点整理-外指赶快先提投降
    简练软考知识点整理-实施整体变更控制过程
    简练软考知识点整理-监控项目工作过程
    简练软考知识点整理-指导与管理项目工作过程
    简练软考知识点整理-制定项目管理计划过程
    Day10文件内指针移动和函数
    Day09文件操作
  • 原文地址:https://www.cnblogs.com/w413133157/p/1730492.html
Copyright © 2020-2023  润新知