- 고정 된 폴더가 아닌 내가 원하는 폴더를 선택하고 원하는 확장자만 가져오는 방식을 알아보려 합니다.
- [ Autoit ] GUI 메뉴 만들기 - 기본편 과 [ Autoit ] 특정 폴더 파일리스트 구해오기#1 - 기본편 에서 사용 된 내용을 결합하면 쉽게 구현이 가능합니다. 먼저 재료를 구해옵니다.
; Create a GUI with various controls.
Local $hGUI = GUICreate("Example")
Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idOK
ExitLoop
EndSwitch
WEnd
; Delete the previous GUI and all controls.
GUIDelete($hGUI)
[ Autoit ] 특정 폴더 파일리스트 구해오기#1 - 기본편
Func Example()
; List all the files and folders in the desktop directory using the default parameters and return the full path.
Local $aFileList = _FileListToArray(@DesktopDir, Default, Default, True)
If @error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
Exit
EndIf
If @error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
Exit
EndIf
; Display the results returned by _FileListToArray.
_ArrayDisplay($aFileList, "$aFileList")
EndFunc ;==>Example
- 내용 결합 후 처음 하는 작업은 Case를 하나더 추가 후 OK 버튼을 하단으로 이동하는 작업을 진행하는 것 입니다.
- 폴더를 선택 할 수 있는 명령어를 추가 합니다. 내가 원하는 폴더를 선택 할 수 있으며, 기본값은 Script 파일이 위치한 곳을 기본으로 열리게 됩니다. 추가로 Error을 방지하기 위한 코드도 추가로 넣어주시면 좋습니다.
- 경로를 선택하는 함수를 추가 하였으므로 해당 값이 전달 될 수 있도록 작업 합니다.
- 여기서 동작을 확인해 보도록 하겠습니다. 내가 선택한 폴더의 파일리스트가 정상적으로 표시 되는 것을 확인 할 수 있습니다.
- 여기에 한가지만 더 추가하면 내가 원하는 확장자만 가져올 수 있습니다. _FileListToArray 의 2번째 항목에 확장자 정보를 업데이트 하면 됩니다. ( 초기 값 : Default )
Local $aFileList = _FileListToArray($select_folder, "*.au3", Default, True)
- 다시 한번 동일하게 동작해서 결과를확인 합니다. 지정한 확장자만 표시되는 것을 확인 할 수 있습니다.
전체 코드
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
;~ #include <MsgBoxConstants.au3>
; Create a GUI with various controls.
Local $hGUI = GUICreate("Example")
Local $idOK_T = GUICtrlCreateButton("OK", 310, 370, 85, 25)
; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idOK_T
$select_folder = FileSelectFolder("Select Folder" , @ScriptDir ,4)
If not @error Then
Example($select_folder)
EndIf
EndSwitch
WEnd
; Delete the previous GUI and all controls.
GUIDelete($hGUI)
Func Example($select_folder)
; List all the files and folders in the desktop directory using the default parameters and return the full path.
Local $aFileList = _FileListToArray($select_folder, "*.au3", Default, True)
If @error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
Exit
EndIf
If @error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
Exit
EndIf
; Display the results returned by _FileListToArray.
_ArrayDisplay($aFileList, "$aFileList")
EndFunc ;==>Example
'RPA 만들기 - 함수 사용법' 카테고리의 다른 글
[ Autoit ] Send로 키보드 값 입력하기 #1 - 기본편 (0) | 2020.09.15 |
---|---|
[ Autoit ] Excel 데이터 추출하여 다른 파일로 재저장 하기 #1 - 기본편 (0) | 2020.09.13 |
[ Autoit ] 특정 폴더 파일리스트 구해오기#1 - 기본편 (0) | 2020.09.10 |
[ Autoit ] 손쉬운 GUI 찾아바꾸기 툴 만들기 (0) | 2020.09.08 |
[ Autoit ] GUI 메뉴 만들기 - 기본편 (0) | 2020.09.06 |