728x90
반응형
File.Move(string,string)
지정된 파일을 새 위치로 이동하고, 새 파일의 이름을 지정할 수 있습니다.
[함수원형]
public static void Move (string sourceFileName, string destFileName);
[Parameters]
이름 | 타입 | 설명 |
sourceFileName | string | 이동할 파일 이름입니다.(경로 포함) |
destFileName | string | 새 경로 및 이름입니다. |
[예]
bool Rename(string src,string dest)
{
if(File.Exists(src)) //소스 파일이 존재하는지 체크 합니다.
{
try
{
File.Move(src,dest); //소스파일을 데스트파일로 이동(이름변경)합니다.
return true;
}
catch(System.Exception e)
print(e.Message); //파일 이름 변경 실패시 처리를 해줍니다.
}
return false;
}
반응형
File.Move(string,string,bool)
지정된 파일을 새 위치로 이동하고, 새 파일의 이름을 지정할 수 있으며 이미존재하는 이름일경우 덮어쓰는 옵션을 제공합니다.
[함수원형]
public static void Move (string sourceFileName, string destFileName, bool overwrite);
[Parameters]
이름 | 타입 | 설명 |
sourceFileName | string | 이동할 파일 이름입니다(경로 포함) |
destFileName | string | 새 경로 및 이름입니다. |
overwrite | bool | 대상 파일을 덮어쓸지 여부 입니다. |
[예]
bool Rename(string src,string dest)
{
if(File.Exists(src)) //소스 파일이 존재하는지 체크 합니다.
{
bool overwrite = false;
if(File.Exist(dest)) //대상 파일이 존재하는지 체크하여 덮어쓰기 유무를 결정합니다.
overwrite = true;
try
{
File.Move(src,dest,overwrite); //소스파일을 데스트파일로 이동(이름변경)합니다.
return true;
}
catch(System.Exception e)
print(e.Message); //파일 이름 변경 실패시 처리를 해줍니다.
}
return false;
}
728x90
반응형
'개발 > C#' 카테고리의 다른 글
[C#]가우스의 등차수열합 공식 (0) | 2020.08.21 |
---|---|
[C#]파일 존재 유무 확인하기 (0) | 2020.08.07 |
[C#]표준 숫자 서식 문자열 (0) | 2020.07.24 |
[C#]MD5 알고리즘 (0) | 2020.06.26 |
[c#]Math.Round (0) | 2020.06.26 |
댓글