Path.Combine メソッド
定義
複数の文字列を 1 つのパスに結合します。Combines strings into a path.
オーバーロード
Combine(String[]) |
文字列の配列を 1 つのパスに結合します。Combines an array of strings into a path. |
Combine(String, String) |
2 つの文字列を 1 つのパスに結合します。Combines two strings into a path. |
Combine(String, String, String) |
3 つの文字列を 1 つのパスに結合します。Combines three strings into a path. |
Combine(String, String, String, String) |
4 つの文字列を 1 つのパスに結合します。Combines four strings into a path. |
注釈
このメソッドは、個々の文字列を、ファイルパスを表す1つの文字列に連結することを目的としています。This method is intended to concatenate individual strings into a single string that represents a file path. ただし、最初の以外の引数にルート化されたパスが含まれている場合、前のパスコンポーネントは無視され、返された文字列はルートパスコンポーネントで始まります。However, if an argument other than the first contains a rooted path, any previous path components are ignored, and the returned string begins with that rooted path component. メソッドの代わりに Combine
、メソッド Join またはメソッドの使用を検討してください TryJoin 。As an alternative to the Combine
method, consider using the Join or TryJoin methods.
重要
このメソッドは、最初の引数が絶対パスであり、次の引数が相対パスであることを前提としています。This method assumes that the first argument is an absolute path and that the following argument or arguments are relative paths. そうでない場合、特に後続の引数がユーザーによって入力された文字列の場合は、 Join 代わりにメソッドまたはメソッドを呼び出し TryJoin ます。If this is not the case, and particularly if any subsequent arguments are strings input by the user, call the Join or TryJoin method instead.
Combine(String[])
文字列の配列を 1 つのパスに結合します。Combines an array of strings into a path.
public:
static System::String ^ Combine(... cli::array <System::String ^> ^ paths);
public static string Combine (params string[] paths);
static member Combine : string[] -> string
Public Shared Function Combine (ParamArray paths As String()) As String
パラメーター
- paths
- String[]
パスの構成要素の配列。An array of parts of the path.
戻り値
結合されたパス。The combined paths.
例外
配列内の文字列の 1 つが、GetInvalidPathChars() で定義された無効な文字を 1 つ以上含んでいます。One of the strings in the array contains one or more of the invalid characters defined in GetInvalidPathChars().
配列内の文字列の 1 つが null
です。One of the strings in the array is null
.
例
次の例では、文字列の配列を1つのパスに結合します。The following example combines an array of strings into a path.
string[] paths = {@"d:\archives", "2001", "media", "images"};
string fullPath = Path.Combine(paths);
Console.WriteLine(fullPath);
Dim paths As String() = {"d:\archives", "2001", "media", "images"}
Dim fullPath As String = Path.Combine(paths)
Console.WriteLine(fullPath)
注釈
paths
は、結合するパスの部分の配列である必要があります。paths
should be an array of the parts of the path to combine. 後続のパスのいずれかが絶対パスの場合、結合操作はその絶対パスで開始され、前に結合されたすべてのパスを破棄してリセットされます。If the one of the subsequent paths is an absolute path, then the combine operation resets starting with that absolute path, discarding all previous combined paths.
のいずれかの要素が、最後の要素がドライブではなく、 paths
またはのいずれかの文字で終了しない場合 DirectorySeparatorChar AltDirectorySeparatorChar 、 Combine
メソッドは DirectorySeparatorChar その要素と次の要素の間に文字を追加します。If any element in paths
but the last one is not a drive and does not end with either the DirectorySeparatorChar or the AltDirectorySeparatorChar character, the Combine
method adds a DirectorySeparatorChar character between that element and the next one. 要素がターゲットプラットフォームに適していないパス区切り文字で終了した場合、メソッドは元の Combine
パス区切り文字を保持し、サポートされているものを追加します。Note that, if the element ends in a path separator character that is not appropriate for the target platform, the Combine
method preserves the original path separator character and appends a supported one. 次の例では、円記号がパスの区切り文字として使用されている場合に、Windows と Unix ベースのシステムの結果を比較します。The following example compares the result on Windows and Unix-based systems when the backslash is used as a path separator character.
string[] paths = {@"d:\archives", "2001", "media", "images"};
string fullPath = Path.Combine(paths);
Console.WriteLine(fullPath);
paths = new string[] {@"d:\archives\", @"2001\", "media", "images"};
fullPath = Path.Combine(paths);
Console.WriteLine(fullPath);
paths = new string[] {"d:/archives/", "2001/", "media", "images"};
fullPath = Path.Combine(paths);
Console.WriteLine(fullPath);
// The example displays the following output if run on a Windows system:
// d:\archives\2001\media\images
// d:\archives\2001\media\images
// d:/archives/2001/media\images
//
// The example displays the following output if run on a Unix-based system:
// d:\archives/2001/media/images
// d:\archives\/2001\/media/images
// d:/archives/2001/media/images
Dim paths As String() = { "d:\archives", "2001", "media", "images" }
Dim fullPath As String = Path.Combine(paths)
Console.WriteLine(fullPath)
paths = { "d:\archives\", "2001\", "media", "images" }
fullPath = Path.Combine(paths)
Console.WriteLine(fullPath)
paths = { "d:/archives/", "2001/", "media", "images" }
fullPath = Path.Combine(paths)
Console.WriteLine(fullPath)
' The example displays the following output if run on a Windows system:
' d:\archives\2001\media\images
' d:\archives\2001\media\images
' d:/archives/2001/media\images
'
' The example displays the following output if run on a Linux system:
' d:\archives/2001/media/images
' d:\archives\/2001\/media/images
' d:/archives/2001/media/images
長さ0の文字列は、組み合わせたパスから省略されます。Zero-length strings are omitted from the combined path.
空白の場合、パラメーターは解析されません。The parameters are not parsed if they have white space.
Combine
検索ワイルドカード文字にはこれらの文字を使用できるため、ディレクトリ名とファイル名に無効な文字が含まれることはありません。Not all invalid characters for directory and file names are interpreted as unacceptable by the Combine
method, because you can use these characters for search wildcard characters. たとえば、では、ファイルを作成するときには無効になる Path.Combine("c:\\", "*.txt")
場合があります。これは、検索文字列として有効です。For example, while Path.Combine("c:\\", "*.txt")
might be invalid if you were to create a file from it, it is valid as a search string. このため、メソッドによって正常に解釈され Combine
ます。It is therefore successfully interpreted by the Combine
method.
こちらもご覧ください
適用対象
Combine(String, String)
2 つの文字列を 1 つのパスに結合します。Combines two strings into a path.
public:
static System::String ^ Combine(System::String ^ path1, System::String ^ path2);
public static string Combine (string path1, string path2);
static member Combine : string * string -> string
Public Shared Function Combine (path1 As String, path2 As String) As String
パラメーター
- path1
- String
結合する 1 番目のパス。The first path to combine.
- path2
- String
結合する 2 番目のパス。The second path to combine.
戻り値
結合されたパス。The combined paths. 指定したパスの 1 つが長さ 0 の文字列の場合、このメソッドは別のパスを返します。If one of the specified paths is a zero-length string, this method returns the other path. path2
に絶対パスが含まれる場合、このメソッドは path2
を返します。If path2
contains an absolute path, this method returns path2
.
例外
path1
または path2
が、GetInvalidPathChars() で定義されている無効な文字を 1 つ以上含んでいます。path1
or path2
contains one or more of the invalid characters defined in GetInvalidPathChars().
path1
または path2
が null
です。path1
or path2
is null
.
例
次の例は、Windows ベースのデスクトッププラットフォームでのメソッドの使用方法を示して Combine
います。The following example demonstrates using the Combine
method on a Windows-based desktop platform.
using namespace System;
using namespace System::IO;
void CombinePaths( String^ p1, String^ p2 )
{
try
{
String^ combination = Path::Combine( p1, p2 );
Console::WriteLine( "When you combine '{0}' and '{1}', the result is: {2}'{3}'", p1, p2, Environment::NewLine, combination );
}
catch ( Exception^ e )
{
if (p1 == nullptr)
p1 = "nullptr";
if (p2 == nullptr)
p2 = "nullptr";
Console::WriteLine( "You cannot combine '{0}' and '{1}' because: {2}{3}", p1, p2, Environment::NewLine, e->Message );
}
Console::WriteLine();
}
int main()
{
String^ path1 = "c:\\temp";
String^ path2 = "subdir\\file.txt";
String^ path3 = "c:\\temp.txt";
String^ path4 = "c:^*&)(_=@#'\\^.*(.txt";
String^ path5 = "";
String^ path6 = nullptr;
CombinePaths( path1, path2 );
CombinePaths( path1, path3 );
CombinePaths( path3, path2 );
CombinePaths( path4, path2 );
CombinePaths( path5, path2 );
CombinePaths( path6, path2 );
}
using System;
using System.IO;
public class ChangeExtensionTest {
public static void Main() {
string path1 = "c:\\temp";
string path2 = "subdir\\file.txt";
string path3 = "c:\\temp.txt";
string path4 = "c:^*&)(_=@#'\\^.*(.txt";
string path5 = "";
string path6 = null;
CombinePaths(path1, path2);
CombinePaths(path1, path3);
CombinePaths(path3, path2);
CombinePaths(path4, path2);
CombinePaths(path5, path2);
CombinePaths(path6, path2);
}
private static void CombinePaths(string p1, string p2) {
try {
string combination = Path.Combine(p1, p2);
Console.WriteLine("When you combine '{0}' and '{1}', the result is: {2}'{3}'",
p1, p2, Environment.NewLine, combination);
} catch (Exception e) {
if (p1 == null)
p1 = "null";
if (p2 == null)
p2 = "null";
Console.WriteLine("You cannot combine '{0}' and '{1}' because: {2}{3}",
p1, p2, Environment.NewLine, e.Message);
}
Console.WriteLine();
}
}
// This code produces output similar to the following:
//
// When you combine 'c:\temp' and 'subdir\file.txt', the result is:
// 'c:\temp\subdir\file.txt'
//
// When you combine 'c:\temp' and 'c:\temp.txt', the result is:
// 'c:\temp.txt'
//
// When you combine 'c:\temp.txt' and 'subdir\file.txt', the result is:
// 'c:\temp.txt\subdir\file.txt'
//
// When you combine 'c:^*&)(_=@#'\^.*(.txt' and 'subdir\file.txt', the result is:
// 'c:^*&)(_=@#'\^.*(.txt\subdir\file.txt'
//
// When you combine '' and 'subdir\file.txt', the result is:
// 'subdir\file.txt'
//
// You cannot combine 'null' and 'subdir\file.txt' because:
// Value cannot be null.
// Parameter name: path1
Imports System.IO
Public Class ChangeExtensionTest
Public Shared Sub Main()
Dim path1 As String = "c:\temp"
Dim path2 As String = "subdir\file.txt"
Dim path3 As String = "c:\temp.txt"
Dim path4 As String = "c:^*&)(_=@#'\\^.*(.txt"
Dim path5 As String = ""
Dim path6 As String = Nothing
CombinePaths(path1, path2)
CombinePaths(path1, path3)
CombinePaths(path3, path2)
CombinePaths(path4, path2)
CombinePaths(path5, path2)
CombinePaths(path6, path2)
End Sub
Private Shared Sub CombinePaths(p1 As String, p2 As String)
Try
Dim combination As String = Path.Combine(p1, p2)
Console.WriteLine("When you combine '{0}' and '{1}', the result is: {2}'{3}'", p1, p2, Environment.NewLine, combination)
Catch e As Exception
If p1 = Nothing Then
p1 = "Nothing"
End If
If p2 = Nothing Then
p2 = "Nothing"
End If
Console.WriteLine("You cannot combine '{0}' and '{1}' because: {2}{3}", p1, p2, Environment.NewLine, e.Message)
End Try
Console.WriteLine()
End Sub
End Class
' This code produces output similar to the following:
'
' When you combine 'c:\temp' and 'subdir\file.txt', the result is:
' 'c:\temp\subdir\file.txt'
'
' When you combine 'c:\temp' and 'c:\temp.txt', the result is:
' 'c:\temp.txt'
'
' When you combine 'c:\temp.txt' and 'subdir\file.txt', the result is:
' 'c:\temp.txt\subdir\file.txt'
'
' When you combine 'c:^*&)(_=@#'\^.*(.txt' and 'subdir\file.txt', the result is:
' 'c:^*&)(_=@#'\^.*(.txt\subdir\file.txt'
'
' When you combine '' and 'subdir\file.txt', the result is:
' 'subdir\file.txt'
'
' You cannot combine '' and 'subdir\file.txt' because:
' Value cannot be null.
' Parameter name: path1
注釈
path1
がドライブ参照 (つまり、"C:" または "D:") ではなく、が、、またはで定義されている有効な区切り文字で終了しない場合は、 DirectorySeparatorChar AltDirectorySeparatorChar VolumeSeparatorChar DirectorySeparatorChar 連結前にがに追加され path1
ます。If path1
is not a drive reference (that is, "C:" or "D:") and does not end with a valid separator character as defined in DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar, DirectorySeparatorChar is appended to path1
before concatenation. が path1
ターゲットプラットフォームに適していないパス区切り文字で終了する場合、 Combine
メソッドは元のパス区切り文字を保持し、サポートされているものを追加します。Note that if path1
ends in a path separator character that is not appropriate for the target platform, the Combine
method preserves the original path separator character and appends a supported one. 次の例では、円記号がパスの区切り文字として使用されている場合に、Windows と Unix ベースのシステムの結果を比較します。The following example compares the result on Windows and Unix-based systems when the backslash is used as a path separator character.
var result = Path.Combine(@"C:\Pictures\", "Saved Pictures");
Console.WriteLine(result);
// The example displays the following output if run on a Windows system:
// C:\Pictures\Saved Pictures
//
// The example displays the following output if run on a Unix-based system:
// C:\Pictures\/Saved Pictures
Dim result = Path.Combine("C:\Pictures\", "Saved Pictures")
Console.WriteLine(result)
' The example displays the following output if run on a Windows system:
' C:\Pictures\Saved Pictures
'
' The example displays the following output if run on a Unix-based system:
' C:\Pictures\/Saved Pictures
path2
にルートが含まれていない場合 (たとえば、 path2
が区切り文字またはドライブ指定で始まらない場合)、結果は2つのパスを連結したものになります。If path2
does not include a root (for example, if path2
does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. に path2
ルートが含まれている場合 path2
は、が返されます。If path2
includes a root, path2
is returned.
空白の場合、パラメーターは解析されません。The parameters are not parsed if they have white space. したがって、 path2
に空白が含まれている場合 (たとえば、"\file.txt")、 Combine メソッドは path2
を返すのではなく、にを追加し path1
path2
ます。Therefore, if path2
includes white space (for example, " \file.txt "), the Combine method appends path2
to path1
instead of returning only path2
.
Combine
検索ワイルドカード文字にはこれらの文字を使用できるため、ディレクトリ名とファイル名に無効な文字が含まれることはありません。Not all invalid characters for directory and file names are interpreted as unacceptable by the Combine
method, because you can use these characters for search wildcard characters. たとえば、では、ファイルを作成するときには無効になる Path.Combine("c:\\", "*.txt")
場合があります。これは、検索文字列として有効です。For example, while Path.Combine("c:\\", "*.txt")
might be invalid if you were to create a file from it, it is valid as a search string. このため、メソッドによって正常に解釈され Combine
ます。It is therefore successfully interpreted by the Combine
method.
共通 I/O タスクの一覧は、 共通 I/O タスク を参照してください。For a list of common I/O tasks, see Common I/O Tasks.
こちらもご覧ください
- Windows システムのファイル パス形式File path formats on Windows systems
- ファイルおよびストリーム入出力File and Stream I/O
- 方法 : ファイルからテキストを読み取るHow to: Read Text from a File
- 方法 : ファイルにテキストを書き込むHow to: Write Text to a File
適用対象
Combine(String, String, String)
3 つの文字列を 1 つのパスに結合します。Combines three strings into a path.
public:
static System::String ^ Combine(System::String ^ path1, System::String ^ path2, System::String ^ path3);
public static string Combine (string path1, string path2, string path3);
static member Combine : string * string * string -> string
Public Shared Function Combine (path1 As String, path2 As String, path3 As String) As String
パラメーター
- path1
- String
結合する 1 番目のパス。The first path to combine.
- path2
- String
結合する 2 番目のパス。The second path to combine.
- path3
- String
結合する 3 番目のパス。The third path to combine.
戻り値
結合されたパス。The combined paths.
例外
path1
、path2
、または path3
が、GetInvalidPathChars() で定義されている無効な文字を 1 つ以上含んでいます。path1
, path2
, or path3
contains one or more of the invalid characters defined in GetInvalidPathChars().
path1
、path2
、または path3
が null
です。path1
, path2
, or path3
is null
.
例
次の例では、3つのパスを結合します。The following example combines three paths.
string p1 = @"d:\archives\";
string p2 = "media";
string p3 = "images";
string combined = Path.Combine(p1, p2, p3);
Console.WriteLine(combined);
Dim p1 As String = "d:\archives\"
Dim p2 As String = "media"
Dim p3 As String = "images"
Dim combined As String = Path.Combine(p1, p2, p3)
Console.WriteLine(combined)
注釈
path1
絶対パスを指定する必要があります (たとえば、"d:\archives" または " \ \archives\public")。path1
should be an absolute path (for example, "d:\archives" or "\\archives\public"). path2
または path3
が絶対パスの場合、結合操作は、以前に結合されたすべてのパスを破棄し、その絶対パスにリセットします。If path2
or path3
is also an absolute path, the combine operation discards all previously combined paths and resets to that absolute path.
長さ0の文字列は、組み合わせたパスから省略されます。Zero-length strings are omitted from the combined path.
path1
または path2
がドライブ参照 (つまり "C:" または "D:") ではなく、が、、またはで定義されている有効な区切り文字で終了していない場合は、 DirectorySeparatorChar 連結前のまたはの前に AltDirectorySeparatorChar VolumeSeparatorChar DirectorySeparatorChar が追加され path1
path2
ます。If path1
or path2
is not a drive reference (that is, "C:" or "D:") and does not end with a valid separator character as defined in DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar, DirectorySeparatorChar is appended to path1
or path2
before concatenation. path1
またはが path2
ターゲットプラットフォームに適していないパス区切り文字である場合、 Combine
メソッドは元のパス区切り文字を保持し、サポートされているものを追加します。Note that if path1
or path2
ends in a path separator character that is not appropriate for the target platform, the Combine
method preserves the original path separator character and appends a supported one. 次の例では、円記号がパスの区切り文字として使用されている場合に、Windows と Unix ベースのシステムの結果を比較します。The following example compares the result on Windows and Unix-based systems when the backslash is used as a path separator character.
var result = Path.Combine(@"C:\Pictures\", @"Saved Pictures\", "2019");
Console.WriteLine(result);
// The example displays the following output if run on a Windows system:
// C:\Pictures\Saved Pictures\2019
//
// The example displays the following output if run on a Unix-based system:
// C:\Pictures\/Saved Pictures\/2019
Dim result = Path.Combine("C:\Pictures\", "Saved Pictures\", "2019")
Console.WriteLine(result)
' The example displays the following output if run on a Windows system:
' C:\Pictures\Saved Pictures\2019
'
' The example displays the following output if run on a Unix-based system:
' C:\Pictures\/Saved Pictures\/2019
path2
にルートが含まれていない場合 (たとえば、 path2
が区切り文字またはドライブ指定で始まらない場合)、結果は2つのパスを連結したものになります。If path2
does not include a root (for example, if path2
does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. に path2
ルートが含まれている場合 path2
は、が返されます。If path2
includes a root, path2
is returned.
空白の場合、パラメーターは解析されません。The parameters are not parsed if they have white space. したがって、 path2
に空白が含まれている場合 (たとえば、"\file.txt")、 Combine メソッドは path2
にを追加し path1
ます。Therefore, if path2
includes white space (for example, " \file.txt "), the Combine method appends path2
to path1
.
Combine
検索ワイルドカード文字にはこれらの文字を使用できるため、ディレクトリ名とファイル名に無効な文字が含まれることはありません。Not all invalid characters for directory and file names are interpreted as unacceptable by the Combine
method, because you can use these characters for search wildcard characters. たとえば、では、ファイルを作成するときには無効になる Path.Combine("c:\\", "*.txt")
場合があります。これは、検索文字列として有効です。For example, while Path.Combine("c:\\", "*.txt")
might be invalid if you were to create a file from it, it is valid as a search string. このため、メソッドによって正常に解釈され Combine
ます。It is therefore successfully interpreted by the Combine
method.
こちらもご覧ください
適用対象
Combine(String, String, String, String)
4 つの文字列を 1 つのパスに結合します。Combines four strings into a path.
public:
static System::String ^ Combine(System::String ^ path1, System::String ^ path2, System::String ^ path3, System::String ^ path4);
public static string Combine (string path1, string path2, string path3, string path4);
static member Combine : string * string * string * string -> string
Public Shared Function Combine (path1 As String, path2 As String, path3 As String, path4 As String) As String
パラメーター
- path1
- String
結合する 1 番目のパス。The first path to combine.
- path2
- String
結合する 2 番目のパス。The second path to combine.
- path3
- String
結合する 3 番目のパス。The third path to combine.
- path4
- String
結合する 4 番目のパス。The fourth path to combine.
戻り値
結合されたパス。The combined paths.
例外
path1
、path2
、path3
、または path4
が、GetInvalidPathChars() で定義されている無効な文字を 1 つ以上含んでいます。path1
, path2
, path3
, or path4
contains one or more of the invalid characters defined in GetInvalidPathChars().
path1
、path2
、path3
、または path4
が null
です。path1
, path2
, path3
, or path4
is null
.
例
次の例では、4つのパスを結合します。The following example combines four paths.
string path1 = @"d:\archives\";
string path2 = "2001";
string path3 = "media";
string path4 = "images";
string combinedPath = Path.Combine(path1, path2, path3, path4);
Console.WriteLine(combinedPath);
Dim path1 As String = "d:\archives\"
Dim path2 As String = "2001"
Dim path3 As String = "media"
Dim path4 As String = "imaged"
Dim combinedPath As String = Path.Combine(path1, path2, path3, path4)
Console.WriteLine(combined)
注釈
path1
絶対パスを指定する必要があります (たとえば、"d:\archives" または " \ \archives\public")。path1
should be an absolute path (for example, "d:\archives" or "\\archives\public"). 後続のパスのいずれかが絶対パスでもある場合、結合操作は以前に結合されたすべてのパスを破棄し、その絶対パスにリセットします。If one of the subsequent paths is also an absolute path, the combine operation discards all previously combined paths and resets to that absolute path.
長さ0の文字列は、組み合わせたパスから省略されます。Zero-length strings are omitted from the combined path.
path1
、、 path2
または path3
がドライブ参照 (つまり "C:" または "D:") ではなく、かつ、、、またはで定義されている有効な区切り文字で終了しない場合は、 DirectorySeparatorChar 連結の前に AltDirectorySeparatorChar VolumeSeparatorChar DirectorySeparatorChar が追加されます。If path1
, path2
, or path3
is not a drive reference (that is, "C:" or "D:") and does not end with a valid separator character as defined in DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar, DirectorySeparatorChar is appended to it before concatenation. path1
、 path2
、またはが path3
ターゲットプラットフォームに適していないパス区切り文字で終了する場合、メソッドは Combine
元のパス区切り文字を保持し、サポートされているものを追加します。Note that if path1
, path2
, or path3
ends in a path separator character that is not appropriate for the target platform, the Combine
method preserves the original path separator character and appends a supported one. 次の例では、円記号がパスの区切り文字として使用されている場合に、Windows と Unix ベースのシステムの結果を比較します。The following example compares the result on Windows and Unix-based systems when the backslash is used as a path separator character.
var result = Path.Combine(@"C:\Pictures\", @"Saved Pictures\", @"2019\", @"Jan\");
Console.WriteLine(result);
// The example displays the following output if run on a Windows system:
// C:\Pictures\Saved Pictures\2019\Jan\
//
// The example displays the following output if run on a Unix-based system:
// C:\Pictures\Saved Pictures\2019\Jan\
Dim result = Path.Combine("C:\Pictures\", "Saved Pictures\", "2019\", "Jan\")
Console.WriteLine(result)
' The example displays the following output if run on a Windows system:
' C:\Pictures\Saved Pictures\2019\Jan\
'
' The example displays the following output if run on a Unix-based system:
' C:\Pictures\Saved Pictures\2019\Jan\
path2
にルートが含まれていない場合 (たとえば、 path2
が区切り文字またはドライブ指定で始まらない場合)、結果は2つのパスを連結したものになります。If path2
does not include a root (for example, if path2
does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. に path2
ルートが含まれている場合 path2
は、が返されます。If path2
includes a root, path2
is returned.
空白の場合、パラメーターは解析されません。The parameters are not parsed if they have white space. したがって、 path2
に空白が含まれている場合 (たとえば、"\file.txt")、 Combine メソッドは path2
にを追加し path1
ます。Therefore, if path2
includes white space (for example, " \file.txt "), the Combine method appends path2
to path1
.
Combine
検索ワイルドカード文字にはこれらの文字を使用できるため、ディレクトリ名とファイル名に無効な文字が含まれることはありません。Not all invalid characters for directory and file names are interpreted as unacceptable by the Combine
method, because you can use these characters for search wildcard characters. たとえば、では、ファイルを作成するときには無効になる Path.Combine("c:\\", "*.txt")
場合があります。これは、検索文字列として有効です。For example, while Path.Combine("c:\\", "*.txt")
might be invalid if you were to create a file from it, it is valid as a search string. このため、メソッドによって正常に解釈され Combine
ます。It is therefore successfully interpreted by the Combine
method.