Scripting Runtime Library(FileSystemObject)

하나 이상의 파일을 기존 위치에서 다른 위치로 옮긴다.

ScriptFileSystemObject.MoveFile(source,destination)
인수/파라메터
object
필수적인 요소이며, 항상 FileSystemObject의 이름이다.
source
필수적인 요소이며, 옮길 파일 경로이다.
source 인수 문자열에는 마지막 경로 구성 요소에만 와일드카드 문자를 사용할 수 있다.
destination
필수적인 요소이며, 파일을 옮길 경로이다.
destination 인수에는 와일드카드 문자를 사용할 수 없다.
반환값

반환값은 없다.

설명

하나 이상의 파일을 기존 위치에서 다른 위치로 옮긴다.

source에 와일드카드를 사용하거나 destination이 경로 구분 기호(\)로 끝나면 destination이 일치하는 파일을 옮길 기존 폴더(Folder)를 나타낸다.

그렇지 않으면 destination은 만들 대상 파일(File)의 이름을 나타낸다.

둘 중 어느 경우라도 개별 파일을 옮길 때 아래 세 가지 중 하나가 일어날 수 있다.

source에 사용한 와일드카드 문자와 일치하는 파일이 없으면 오류가 발생한다.
MoveFile 메서드는 첫 번째 오류가 발생하면 그 상태로 중지한다.
오류가 발생하고 나면 이전에 변경된 사항은 되돌릴 수 없다.

참고: 운영 체제가 지원하는 경우에만 이 메서드를 사용하여 볼륨들 간에 파일을 옮길 수 있다.

method
MoveFile 메서드
MoveFile</b> 메서드이전페이지로페이지 맨위로페이지 맨아래로

MoveFile 메서드 예제

결과 표시창
JScript MoveFile 메서드 예제
<SCRIPT language=JScript>
function MoveFileTest(filePath,destination){
  str='';
  var fso=new ActiveXObject('Scripting.FileSystemObject');
  if (!fso.FileExists(filePath)){
    fileObj=fso.OpenTextFile(filePath,2,true);
    fileObj.WriteLine('예제를 위한 파일이다.');
    fileObj.Close();
    str+='원본 파일이 없어 '+filePath+' 파일을 생성하였다.<BR>';
  }
  if (!fso.FolderExists(destination)){
    fso.CreateFolder(destination);
    str+='복사 폴더가 없어 '+destination+' 폴더를 생성하였다.<BR>';
  }
  targetFile=destination+'\\'+fso.GetFileName(filePath);
  if (fso.FileExists(targetFile)){
    fso.DeleteFile(targetFile);
    str+='복사 파일이 있어 '+targetFile+' 파일을 삭제하였다.<BR>';
  }

  fso.MoveFile(filePath,destination);
  str+='원본 '+filePath+' 파일을 '+destination+'으로 이동하였다.';
  return(str);
}
</SCRIPT>

<DIV id=showjs class=show alt="결과">결과 표시창</DIV>
<DIV class=show
  onClick="id=showjs.innerHTML=MoveFileTest('C:\\JsTest\\CreateText.txt','C:\\JsTest\\test\\')">
  <SPAN class=ie>JScript</SPAN> <SPAN class=method>MoveFile</SPAN> 메서드 예제</DIV>
결과 표시창
VBScript MoveFile 메서드 예제
<SCRIPT language=VBScript>
Function MoveFileTestvb(filePath,destination)
  Dim fso,targetFile
  str=""
  Set fso=CreateObject("Scripting.FileSystemObject")
  If Not fso.FileExists(filePath) Then
    Set fileObj=fso.OpenTextFile(filePath,2,True)
    fileObj.WriteLine "예제를 위한 파일이다."
    fileObj.Close
    str=str&"원본 파일이 없어 "&filePath&" 파일을 생성하였다.<BR>"
  End If

  If Not fso.FolderExists(destination) Then
    fso.CreateFolder(destination)
    str=str&"복사 폴더가 없어 "&destination&" 폴더를 생성하였다.<BR>"
  End If

  targetFile=destination&"\"&fso.GetFileName(filePath)
  If fso.FileExists(targetFile) Then
    fso.DeleteFile(targetFile)
    str=str&"복사 파일이 있어 "&targetFile&" 파일을 삭제하였다.<BR>"
  End If

  fso.MoveFile drivePath,destination
  str=str&"원본 "&filePath&" 파일을 "&destination&"으로 이동하였다."

  MoveFileTestvb=str
End Function
</SCRIPT>

<DIV id=showvb class=show alt="결과">결과 표시창</DIV>
<DIV class=show
 onClick="showvb.innerHTML=MoveFileTestvb('C:\\JsTest\\CreateText.txt','C:\\JsTest\\test\\')">
  <SPAN class=ie>VBScript</SPAN> <SPAN class=method>MoveFile</SPAN> 메서드 예제</DIV>

method
MoveFile 메서드
견본
이전페이지로페이지 맨위로
최종 수정:
05/13/2025 12:27:32
KoXo Homepage
All right reserved
비정상적인 방식으로 프레임없이 페이지에 접속하면 자주 오류가 발생됩니다.
오류가 나면 정상적 접속으로 시도해 보세요.
http://koxo.com/lang/js/method/MoveFile.html