zoukankan      html  css  js  c++  java
  • Delphi 获取指定文件的驱动器名, 文件夹名, 路径名, 文件名

    var
      fullFileName : string;
    
    begin
      // Set up a full file name with drive and path
      fullFileName := 'C:\Program Files\Borland\Delphi7\Projects\Unit1.dcu';
    
      // Show the component parts of this full name
      ShowMessage('Drive = '+ExtractFileDrive (fullFileName));
      ShowMessage('Dir   = '+ExtractFileDir   (fullFileName));
      ShowMessage('Path  = '+ExtractFilePath  (fullFileName));
      ShowMessage('Name  = '+ExtractFileName  (fullFileName));
      ShowMessage('Ext   = '+ExtractFileExt   (fullFileName));
    end;
    Drive = C:
    Dir   = C:\Program Files\Borland\Delphi7\Projects
    Path  = C:\Program Files\Borland\Delphi7\Projects\
    Name  = Unit1.dcu
    Ext   = .dcu

    //获取应程序文件的路径
    ExtractFilePath(Application.ExeName);

    var
      oldName, newName : string;
    
    begin
      // Try to rename the current Unit1.dcu to Uni1.old
      oldName := 'Unit1.dcu';
      newName := ChangeFileExt(oldName, '.new');
    
      // Show the old and new values
      ShowMessage('Old name = '+oldName);
      ShowMessage('New name = '+newName);
    end;
    Old name = Unit1.dcu
    New name = Unit1.new
    var
      selectedFile   : string;
      drive          : char;
      path, fileName : string;
    
    begin
      // Ask the user to select a file
      if PromptForFileName(selectedFile)
      then
      begin
        // Display this full file/path value
        ShowMessage('Selected file = '+selectedFile);
    
        // Split this full file/path value into its constituent parts
        ProcessPath(selectedFile, drive, path, fileName);
        ShowMessage('drive = '+drive);
        ShowMessage('path = '+path);
        ShowMessage('fileName = '+fileName);
      end;
    end;
     { The user selects C:\Files\data.txt and hits OK }
       
       Selected file = C:\Files\data.txt
       drive = C
       path = \Files
       filename = data.txt

    http://www.delphibasics.co.uk/index.html


  • 相关阅读:
    代腾飞(为自己名字作诗)
    愈到老愈受用:人生成功生涯规划100诀
    漫步白沫江畔有感
    成功自有成功的方法和道理(一堂价值百万的课)
    你的终点在哪里?决定成功与否的十种智力
    为你痴狂
    苏竹青(帮别人名字作诗)
    何韵仪(帮别人名字作诗)
    腹有诗书又如何
    漫步茶马古道有感
  • 原文地址:https://www.cnblogs.com/shangdawei/p/3050238.html
Copyright © 2011-2022 走看看