Delphi 파일의 읽기와 쓰기 작업

10586 단어
delphi 파일 작업
    
ExtractFileName(FileName);
      :
ExtractFileExt(filename);
    ,     :

   :

Function ExtractFileNameNoExt(FileString: String): String;
Var
  FileWithExtString: String;
  FileExtString: String;
  LenExt: Integer;
  LenNameWithExt: Integer;
Begin
  FileWithExtString := ExtractFileName(FileString);
  LenNameWithExt    := Length(FileWithExtString);  FileExtString     := ExtractFileExt(FileString);   LenExt            := Length(FileExtString);
  If LenExt = 0 Then 
     Begin
       Result := FileWithExtString;
     End
     Else
      Begin
       Result := Copy(FileWithExtString,1,(LenNameWithExt-LenExt)); 
      End;
 End;
   :

ChangeFileExt(ExtractFileName(Application.ExeName),'')

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



//delphi         

ExtractFileDrive :            , "C:"
ExtractFilePath:           ,   “/”, "C:/test/"
ExtractFileDir:           ,    “/” , "C:/test"
ExtractFileName:              (    ), "mytest.doc"
ExtractFileExt               ( .), ".doc"

ExtractRelativePath :       ,    :
function ExtractRelativePath(const BaseName, DestName: string): string;
      :
SysUtils.ExtractRelativePath('C:/test','C:/Test/TestRelativePath'):  TestRelativePath
SysUtils.ExtractRelativePath('C:/Test/TestRelativePath','C:/test'):  '../TestRelativePath'
SysUtils.ExtractRelativePath('C:/Test/TestRelativePath/','C:/test'):  '../../TestRelativePath'
ExtractShortPathName :      , 8+3,      ,    3 ,   DOS       
 
            ,  :
ChangeFileExt(TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename,'');           .          ,        ?   
 
 
         :
 
1、      
               、     、            。            。 
      
ExpandFileName()         (    、  ) 
ExtractFileExt()            
ExtractFileName()                 
ExtractFilePath()            
ExtractFileDir()            
ExtractFileDrive()             
ChangeFileExt()          
ExpandUNCFileName()                 
ExtractRelativePath()               
ExtractShortPathName()        DOS 8·3   
MatchesMask()                  
ExtractFilePath(FileName:String)
        ,       “/”
ExtractFileDir(FileName:String)
          ,         “/”,           。
               : 
⑴ExpandFileName() 
    :extern PACKAGE AnsiString __fastcall ExpandFileName(const AnsiString FileName); 
    :        (    、  ) 
    :FileName:        
   :ShowMessage(ExpandFileName(Application->ExeName));//         , C:/MyBCB/Sample1.EXE 
⑵ExtractFileExt() 
    :extern PACKAGE AnsiString __fastcall ExtractFileExt(const AnsiString FileName); 
    :           
    :FileName:       (   ) 
   :ShowMessage(ExtractFileExt(Application->ExeName));//  ".exe" 
⑶ExtractFileName() 
    :extern PACKAGE AnsiString __fastcall ExtractFileName(const AnsiString FileName); 
    :                
    :FileName:        
   :ShowMessage(ExtractFileExt("c://Winnt//SOL.EXE"));//  "SOL.EXE" 
⑷ExtractFilePath() 
    :extern PACKAGE AnsiString __fastcall ExtractFilePath(const AnsiString FileName); 
    :           
    :FileName:        
   :ShowMessage(ExtractFilePath("Winnt//SOL.EXE"));//  "Winnt/" 
⑸ExtractFileDir() 
    :extern PACKAGE AnsiString __fastcall ExtractFileDir(const AnsiString FileName); 
    :          (       ,      "/") 
    :FileName:        
   :ShowMessage(ExtractFileDir("Winnt//SOL.EXE"));//  "Winnt",           
⑹ExtractFileDrive() 
    :extern PACKAGE AnsiString __fastcall ExtractFileDrive(const AnsiString FileName); 
    :            
    :FileName:        
   :ShowMessage(ExtractFileDrive("c://Winnt//SOL.EXE"));//  "c:" 
⑺ChangeFileExt() 
    :extern PACKAGE System::AnsiString __fastcall ChangeFileExt(const System::AnsiString FileName, const System::AnsiString Extension); 
    :         ,            ,                
    :FileName:       ,Extension:      
   :ShowMessage(ChangeFileExt("c://Winnt//SOL.EXE",".OOO"));//  "c:/winnt/SOL.OOO" 
⑻ExpandUNCFileName() 
    :extern PACKAGE AnsiString __fastcall ExpandUNCFileName(const AnsiString FileName); 
    :               ,   ://   /   /    
    :FileName:        
   :ShowMessage(ExpandUNCFileName("F://Winnt//SOL.EXE"));/*  F:         ,   "
⑼ExtractRelativePath() 
    :extern PACKAGE AnsiString __fastcall ExtractRelativePath(const AnsiString BaseName, const AnsiString DestName); 
    :             , "../sss/ss.asd"     
    :BaseName:     ;DestName:      
   :ShowMessage(ExtractRelativePath("D://Source//c//1.123","D://Source//Asm//dz.asm"));/*  "../asm/dz.asm"*/ 
⑽ExtractShortPathName() 
    :extern PACKAGE AnsiString __fastcall ExtractShortPathName(const AnsiString FileName); 
    :       DOS 8、3   
    :FileName:        
   :ShowMessage(ExtractShortPathName("E://Program Files//Dual Wheel Mouse//4dmain.exe"));/*  "E:/Progra~1/dualwh~1/4dmain.exe"*/ 
⑾MatchesMask() 
    :extern PACKAGE bool __fastcall MatchesMask(const AnsiString Filename, const AnsiString Mask); 
    :                  
    :FileName:       ;Mask:     ,      
   :ShowMessage(MatchesMask("Lxf.exe","*.?x?));//  "true" 

 
 
 
네트워크에서 유래하다.

좋은 웹페이지 즐겨찾기