• 고정 된 폴더가 아닌 내가 원하는 폴더를 선택하고 원하는 확장자만 가져오는 방식을 알아보려 합니다.

 

[ Autoit ] GUI 메뉴 만들기 - 기본편 

    ; 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

+ Recent posts