SplitPath

ファイル名やURLを、名前、ディレクトリ、拡張子、ドライブに分離します。

SplitPath Path , &OutFileName, &OutDir, &OutExtension, &OutNameNoExt, &OutDrive

パラメータ

Path

型:文字列

解析対象のファイル名またはURL。

この関数は、ファイル名のパスにはバックスラッシュ(\)だけを、URLにはフォワードスラッシュ(/)だけを含むことを想定していることに注意してください。

&OutFileName

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the file name without its path. ファイルの拡張子も含まれる。

&OutDir

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the directory of the file, including drive letter or share name (if present). ファイルがドライブのルート・ディレクトリにある場合でも、最後のバックスラッシュは含まれない。

&OutExtension

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the file's extension (e.g. TXT, DOC, or EXE). ドットは含まれない。

&OutNameNoExt

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the file name without its path, dot and extension.

&OutDrive

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify a reference to the output variable in which to store the drive letter or server name of the file. ファイルがローカルまたはマップされたドライブにある場合、変数にはドライブ文字に続いてコロン(バックスラッシュなし)が設定される。ファイルがネットワークパス(UNC)上にある場合、変数には共有名が設定される。

備考

対応する情報が不要な場合は、出力変数のいずれかを省略することができる。

Pathにドライブ文字がないファイル名(つまり、パスがないか、単に相対パス)が含まれている場合、OutDriveは空白になるが、他のすべての出力変数は正しく設定される。同様に、パスが存在しない場合、OutDirは空白になり、パスが存在するがファイル名が存在しない場合、OutFileNameOutNameNoExtは空白になる。

ファイルシステム内の実際のファイルやディレクトリは、この機能ではチェックされない。これは単純に提供された文字列を解析するだけである。

コロン、バックスラッシュ、ピリオド(ドット)を除き、ワイルドカード(*と?)およびファイル名で不正なその他の文字は、正規の文字と同様に扱われ、ファイルのドライブ文字、ディレクトリ、および拡張子を区切る際の性質に従って処理されます。

URLのサポート: Path"https://domain.com""ftp://domain.com"のようにコロン-ダブルスラッシュを含む場合、OutDirはプロトコルプレフィックス+ドメイン名+ディレクトリ(例:https://domain.com/images)に設定され、OutDriveはプロトコルプレフィックス+ドメイン名(例:https://domain.com)に設定されます。その他の変数は、上記の定義に従って設定される。

A_LoopFileExt, StrSplit, InStr, SubStr, FileSelect, DirSelect

さまざまな使い方を実演します。

FullFileName := "C:\My Documents\Address List.txt"
   
; To fetch only the bare filename from the above:
SplitPath FullFileName, &name

; To fetch only its directory:
SplitPath FullFileName,, &dir

; To fetch all info:
SplitPath FullFileName, &name, &dir, &ext, &name_no_ext, &drive
   
; The above will set the variables as follows:
; name = Address List.txt
; dir = C:\My Documents
; ext = txt
; name_no_ext = Address List
; drive = C: