FileMove

파일을 이동합니다.

FileMove, SourcePattern, DestPattern , Overwrite

매개변수

SourcePattern

단일 파일의 이름 또는 "C:\Temp\*.tmp"와 같은 와일드카드 패턴. SourcePattern은 절재 경로가 지정되어 있지 않으면 %A_WorkingDir%에 있다고 간주됩니다.

DestPattern

목표의 이름이나 패턴, 절대 경로가 지정되지 않으면 %A_WorkingDir%에 있다고 간주됩니다.

If present, the first asterisk (*) in the filename is replaced with the source filename excluding its extension, while the first asterisk after the last full stop (.) is replaced with the source file's extension. If an asterisk is present but the extension is omitted, the source file's extension is used.

To perform a simple move -- retaining the existing file name(s) -- specify only the folder name as shown in these mostly equivalent examples:

FileMove, C:\*.txt, C:\My Folder
FileMove, C:\*.txt, C:\My Folder\*.*

목표 디렉토리는 이미 존재해야 합니다. If My Folder does not exist, the first example above will use "My Folder" as the target filename, while the second example will move no files.

Overwrite

This parameter determines whether to overwrite files if they already exist. If this parameter is 1 (true), the command overwrites existing files. If omitted or 0 (false), the command does not overwrite existing files.

이 매개변수는 표현식일 수 있습니다. 심지어 거짓이나 참으로 평가되면 무엇이든 될 수 있습니다 (참과 거짓은 내부적으로 1과 0으로 저장되기 때문입니다).

에러 처리

[v1.1.04+]: 이 명령어는 실패하면 예외를 던질 수 있습니다. 더 자세한 정보는 실행시간 에러를 참조하십시오.

ErrorLevel은 에러 때문에 이동에 실패한 파일의 개수가 설정됩니다. 그렇지 않으면 0이 설정됩니다. 그렇지만, 소스 파일이 단일 파일이고 (와일드카드 없음) 그리고 존재하지 않으면, ErrorLevel은 0이 설정됩니다. 이 상황을 탐지하려면 이동하기 전에 먼저 소스파일에 FileExist() 또는 IfExist를 사용하십시오.

FileCopy와 다르게, 파일을 자신에 이동하면 언제나 성공한 것으로 간주됩니다. 덮어쓰기 모드가 켜져 있지 않아도 마찬가지입니다.

파일이 발견되면, A_LastError는 0 (0) 또는 마지막 실패 후에 곧바로 운영 체제의 GetLastError() 함수의 결과가 설정됩니다. 그렇지 않으면 A_LastError에는 왜 파일이 발견되지 않았는지 알려주는 에러 코드가 담깁니다.

논평

FileMove는 파일만 이동합니다. 대신 폴더의 내용을 (그의 모든 파일과 하위 폴더를 포함하여) 이동하려면, 아래 섹션의 예제를 참조하십시오. 단일 폴더를 이동하거나 이름을 바꾸려면, FileMoveDir을 사용하십시오.

에러를 만나도 연산은 멈추지 않습니다.

이 명령어는 파일을 다른 볼륨에 이동시킬 수 있지만, 같은-볼륨 이동보다 시간이 더 걸립니다. 이것은 같은-볼륨 이동은 이름을 바꾸는 것과 비슷하고, 그래서 훨씬 더 빠르기 때문입니다.

FileCopy, FileCopyDir, FileMoveDir, FileDelete

예제

Moves a file without renaming it.

FileMove, C:\My Documents\List1.txt, D:\Main Backup\

Renames a single file.

FileMove, C:\File Before.txt, C:\File After.txt

Moves text files to a new location and gives them a new extension.

FileMove, C:\Folder1\*.txt, D:\New Folder\*.bkp

한 폴더 안의 모든 파일과 폴더를 다른 폴더로 이동합니다.

ErrorCount := MoveFilesAndFolders("C:\My Folder\*.*", "D:\Folder to receive all files & folders")
if (ErrorCount != 0)
    MsgBox %ErrorCount% files/folders could not be moved.

MoveFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
; SourcePattern에 부합하는 모든 파일과 폴더를 DestinationFolder 이름의 폴더에 이동하고
; 이동에 실패한 파일/폴더의 개수를 돌려줍니다.
; 이 함수는 FileMoveDir의 모드 2를 사용하기 때문에 [v1.0.38+]이 필요합니다.
; because it uses FileMoveDir's mode 2.
{
    if (DoOverwrite = 1)
        DoOverwrite := 2  ; mode 2 vs. 1 사이의 설명은 FileMoveDir을 참조하십시오.
    ; 먼저 모든 파일을 이동합니다 (폴더는 이동하지 않습니다):
    FileMove, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
    ErrorCount := ErrorLevel
    ; 이제 모든 폴더를 이동합니다:
    Loop, %SourcePattern%, 2  ; 2의 뜻은 "폴더만 열람한다"는 뜻입니다.
    {
        FileMoveDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
        ErrorCount += ErrorLevel
        if ErrorLevel  ; 문제의 폴더를 이름으로 보고합니다.
            MsgBox Could not move %A_LoopFileFullPath% into %DestinationFolder%.
    }
    return ErrorCount
}