Directory.Move(String, String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파일 또는 디렉터리 및 해당 내용을 새 위치로 이동합니다.
public:
static void Move(System::String ^ sourceDirName, System::String ^ destDirName);
public static void Move(string sourceDirName, string destDirName);
static member Move : string * string -> unit
Public Shared Sub Move (sourceDirName As String, destDirName As String)
매개 변수
- sourceDirName
- String
이동할 파일 또는 디렉터리의 경로입니다.
- destDirName
- String
새 위치 또는 해당 내용에 대한 sourceDirName 경로입니다. 파일인 경우 sourceDirName 파일 destDirName 이름이기도 합니다.
예외
디렉터리를 다른 볼륨으로 이동하려고 했습니다.
-또는-
destDirName 이미 존재합니다. 주의 섹션의 메모를 참조하세요.
-또는-
및 destDirName 매개 변수는 sourceDirName 동일한 파일 또는 디렉터리를 참조합니다.
-또는-
디렉터리 또는 파일 내의 파일이 다른 프로세스에서 사용되고 있습니다.
호출자에게 필요한 권한이 없습니다.
.NET Framework 및 .NET Core 버전 2.1 이전 버전: sourceDirName 또는 destDirName 길이가 0인 문자열이거나, 공백만 포함하거나, 하나 이상의 잘못된 문자를 포함합니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars() 수 있습니다.
sourceDirName 또는 destDirName .입니다 null.
지정된 경로, 파일 이름 또는 둘 다 시스템 정의 최대 길이를 초과합니다.
지정한 sourceDirName 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있는 경우).
예제
다음 예제에서는 디렉터리와 모든 해당 파일을 새 디렉터리로 이동하는 방법을 보여 줍니다. 원래 디렉터리는 이동된 후에 더 이상 존재하지 않습니다.
using System;
using System.IO;
partial class Program
{
static void DirectoryMoveExample()
{
string sourceDirectory = @"C:\source";
string destinationDirectory = @"C:\destination";
try
{
Directory.Move(sourceDirectory, destinationDirectory);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
open System.IO
let sourceDirectory = @"C:\source"
let destinationDirectory = @"C:\destination"
try
Directory.Move(sourceDirectory, destinationDirectory)
with e ->
printfn $"{e.Message}"
Imports System.IO
Partial Class Program
Shared Sub DirectoryMoveExample()
Dim sourceDirectory As String = "C:\source"
Dim destinationDirectory As String = "C:\destination"
Try
Directory.Move(sourceDirectory, destinationDirectory)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
End Class
설명
이 메서드는 지정된 destDirName 이름으로 새 디렉터리를 만들고 파일 및 디렉터리를 포함한 내용을 sourceDirName새로 만든 대상 디렉터리로 이동합니다. 그런 다음 디렉터리를 삭제합니다 sourceDirName .
디렉터리를 이미 있는 IOException 디렉터리로 이동하려고 하면 발생합니다.
및 destDirName 인수는 sourceDirName 상대 경로 또는 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리를 기준으로 해석됩니다. 현재 작업 디렉터리를 가져오려면 다음을 참조하세요 GetCurrentDirectory.
후행 공백은 디렉터리를 이동하기 전에 경로 매개 변수의 끝에서 제거됩니다.
일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.
메모
.NET Core 3.0부터 메서드는 Move 이미 있는 경우 destDirName 모든 플랫폼에서 throw IOException 합니다.
C++ 이름 바꾸기를 참조하세요.