본문 바로가기
만드는 이야기/기타

오토핫키) loop 일반 루프, 파일 갯수만큼 루프

by LillyLt 2014. 3. 13.
Loop (normal)Perform a series of commands repeatedly: either the specified number of times or until break is encountered.
Loop (files & folders)Retrieves the specified files or folders, one at a time.
Loop (parse a string)Retrieves substrings (fields) from a string, one at a time.
Loop (read file contents)Retrieves the lines in a text file, one at a time (performs better than FileReadLine).
Loop (registry)Retrieves the contents of the specified registry subkey, one item at a time.

;참조 http://infoki.net/826
;일반 루프
;Loop [, Count]

Loop  ; 무할루프를 돕니다. (아무것도 정해지지 않으면 여기에  Loop[, Count] 처럼되면 그 갯수만큼만 루프)
{
  if A_Index >= 10  ; 루프가 10 번을 돌거나 넘어서면 ...
    break  ; 현재 루프를 빠져나와라
}
Loop, 3
{
    MsgBox, Iteration number is %A_Index%.  ; A_Index will be 1, 2, then 3
    Sleep, 100
}

Loop
{
    if a_index > 25
        break  ; Terminate the loop
    if a_index < 20
        continue ; Skip the below and start a new iteration
    MsgBox, a_index = %a_index% ; This will display only the numbers 20 through 25
}

;파일폴더 루프

;Loop, FilePattern [, IncludeFolders?, Recurse?]


;폴더나 파일갯수 만큼 루프


Loop , %A_ProgramFiles%\*.txt, , 1  ; 이 옵션은 프로그램파일 폴더의 서브폴더 까지 모두 포함
{
  FileTxtList = %FileTxtList%`n%A_LoopFileFullPath%  ; FileTxtList 라는 변수에 확인한 파일을 계속 적재 한다.
  MsgBox, 4, , Filename = %A_LoopFileFullPath%`n`n 계속?  ; 확인한 파일을 보여주고 중지할 것인지 묻는다.
  IfMsgBox, No                                                                ;  이 부분은 전번 강좌에 있으므로 ...
      break                                                                        ; 안보겠다면 중지한다.
}

Msgbox, %FileTxtList%    ;  적대된 파일을 MsgBox 창으로 보여준다.. 너무 많으면  무리가 있으므로 적당히...

;%A_ProgramFiles편입변수 시스템드라이브의 C:\Program Files 를 결과적으로 가르킨다.
;    끝에 1  옵션이 서브폴더 모두라는 명령어 옵션이다. 이번 기회에 모든 JPG 파일을 검색해서 파일로 
;    담아보도록 하겠습니다.


Parameters

FilePattern

The name of a single file or folder, or a wildcard pattern such as C:\Temp\*.tmp. FilePattern is assumed to be in %A_WorkingDir%if an absolute path isn't specified.

Both asterisks and question marks are supported as wildcards. A match occurs when the pattern appears in either the file's long/normal name or its 8.3 short name.

If this parameter is a single file or folder (i.e. no wildcards) and Recurse is set to 1, more than one match will be found if the specified file name appears in more than one of the folders being searched.

IncludeFolders?

One of the following digits, or blank to use the default:
0 (default) Folders are not retrieved (only files). 파일만,폴더는 제외
1 All files and folders that match the wildcard pattern are retrieved.
2 Only folders are retrieved (no files).

다음 숫자 중 하나, 또는 기본 사용하기 빈 : 
0 (기본값) 폴더는 검색되지 않습니다 (파일 만). 
1 와일드 카드 패턴과 일치하는 모든 파일 및 폴더를 검색 할 수 있습니다. 
2 만 폴더가 검색됩니다 (아무 파일).

Recurse?One of the following digits, or blank to use the default:
0 (default) Subfolders are not recursed into. 하위폴더 비포함
1 Subfolders are recursed into so that files and folders contained therein are retrieved if they match FilePattern. All subfolders will be recursed into, not just those whose names match FilePattern.
하위 폴더 포함



Special Variables Available Inside a File-Loop

The following variables exist within any file-loop. If an inner file-loop is enclosed by an outer file-loop, the innermost loop's file will take precedence:

A_LoopFileNameThe name of the file or folder currently retrieved (without the path).
경로 없이 파일이나 폴더 이름
A_LoopFileExtThe file's extension (e.g. TXT, DOC, or EXE). The period (.) is not included.
확장자 없이
A_LoopFileFullPathThe full path and name of the file/folder currently retrieved. However, if FilePattern contains a relative path rather than an absolute path, the path here will also be relative. In addition, any short (8.3) folder names in FilePattern will still be short (see next item to get the long version).
상대경로?
A_LoopFileLongPathThis is different than A_LoopFileFullPath in the following ways: 1) It always contains the absolute/complete path of the file even if FilePattern contains a relative path; 2) Any short (8.3) folder names in FilePattern itself are converted to their long names; 3) Characters in FilePattern are converted to uppercase or lowercase to match the case stored in the file system. This is useful for converting file names -- such as those passed into a script as command line parameters -- to their exact path names as shown by Explorer.
전체경로?
A_LoopFileShortPath

The 8.3 short path and name of the file/folder currently retrieved. For example: C:\MYDOCU~1\ADDRES~1.txt. However, ifFilePattern contains a relative path rather than an absolute path, the path here will also be relative.

To retrieve the complete 8.3 path and name for a single file or folder, specify its name for FilePattern as in this example:

Loop, C:\My Documents\Address List.txt
    ShortPathName = %A_LoopFileShortPath%

NOTE: This variable will be blank if the file does not have a short name, which can happen on systems where NtfsDisable8dot3NameCreation has been set in the registry. It will also be blank if FilePattern contains a relative path and the body of the loop uses SetWorkingDir to switch away from the working directory in effect for the loop itself.

A_LoopFileShortNameThe 8.3 short name, or alternate name of the file. If the file doesn't have one (due to the long name being shorter than 8.3 or perhaps because short-name generation is disabled on an NTFS file system), A_LoopFileName will be retrieved instead.
A_LoopFileDirThe full path of the directory in which A_LoopFileName resides. However, if FilePattern contains a relative path rather than an absolute path, the path here will also be relative. A root directory will not contain a trailing backslash. For example: C:
A_LoopFileTimeModifiedThe time the file was last modified. Format YYYYMMDDHH24MISS.
A_LoopFileTimeCreatedThe time the file was created. Format YYYYMMDDHH24MISS.
A_LoopFileTimeAccessedThe time the file was last accessed. Format YYYYMMDDHH24MISS.
A_LoopFileAttribThe attributes of the file currently retrieved.
A_LoopFileSizeThe size in bytes of the file currently retrieved. Files larger than 4 gigabytes are also supported.
A_LoopFileSizeKBThe size in Kbytes of the file currently retrieved, rounded down to the nearest integer.
A_LoopFileSizeMBThe size in Mbytes of the file currently retrieved, rounded down to the nearest integer.