; Creates files from a list in a text file ; ; Source file musrt have one file per line. File names are not validated. ; ; Created using AutoIt Version: 3.0 #INCLUDE ; Main window size $width = 400; $height = 180; ; Main window $window_main = GUICreate( "Auto file creator", $width, $height, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, $WS_EX_ACCEPTFILES ) ; Accepts drag-and-drop operations ; File input GUICtrlCreateLabel("Pick the source file:", 5, 10) $file = GUICtrlCreateInput ( "", 5, 25, 300, 20) ; This element accepts file drag and drop GUICtrlSetState ( $file, $GUI_ACCEPTFILES ) $button_file = GUICtrlCreateButton("Browse...", 315, 20, 60) ; Directory input GUICtrlCreateLabel("Pick the destination directory:", 5, 60) $dir = GUICtrlCreateInput ( "", 5, 75, 300, 20) $button_dir = GUICtrlCreateButton("Browse...", 315, 70, 60) ; File extension GUICtrlCreateLabel("Enter output file extension (no dot):", 5, 110) $extension = GUICtrlCreateInput ( "txt", 5, 125, 30, 20) ; Buttons $button_ok = GUICtrlCreateButton("OK", $width-130, $height-30, 60) $button_cancel = GUICtrlCreateButton("Cancel", $width-65, $height-30, 60) GUISetState(@SW_SHOW) ; Main window loop WHILE 1 $msg = GUIGetMsg() SELECT ; Open file selector CASE $msg = $button_file $file_name = FileOpenDialog( 'Please choose source file', @ScriptDir, "All (*.*)", 1 + 2 ) IF NOT( @error ) THEN GUICtrlSetData ( $file, $file_name ) EndIf ; Open directory selector CASE $msg = $button_dir $output_dir = FileSelectFolder ( "Please choose target directory", "/", 1+2+4 , @ScriptDir ) IF NOT( @error ) THEN GUICtrlSetData ( $dir, $output_dir ) EndIf ; Execute process CASE $msg = $button_ok ; Check for file name $file_name = GUICtrlRead( $file ); IF $file_name = '' THEN MsgBox( 16 + 8192 + 262144,"Error","No file chosen.") ELSE ; Check for valid file IF not( FileExists ( $file_name ) ) THEN MsgBox( 16 + 8192 + 262144, "Error", "File " & $file_name & " could not be found") ELSE ; Check for directory $output_dir = GUICtrlRead( $dir ); IF $output_dir = '' THEN MsgBox( 16 + 8192 + 262144,"Error","No directory chosen.") ELSE ; Check for valid directory If DirGetSize( $output_dir ) = -1 THEN ; Invalid directory MsgBox( 16 + 8192 + 262144, "Error", "Directory " & $output_dir & " could not be found") ELSE ; Got file and directory, so continue EXITLOOP ENDIF ENDIF ENDIF ENDIF ; Cancel button (exit) CASE $msg = $button_cancel EXIT ; Exit button CASE $msg = $GUI_EVENT_CLOSE EXIT ENDSELECT WEND ; Read file $file = FileOpen ( $file_name, 0 ) ; Get file extension $extension = GUICtrlRead( $extension ); IF NOT( $extension = '' ) THEN $extension = "." & $extension ELSE $extension = '' ENDIF ; Create files WHILE 1 ; Read file name $new_file_name = FileReadLine ( $file ) ; EOF IF @error = -1 THEN EXITLOOP ; Create new file $new_file = FileOpen ( $output_dir & '\' & $new_file_name & $extension, 1 ) ; Close it FileClose ( $new_file ) WEND ; Close file list FileClose ( $file ) ; Tell 'em it's over MsgBox( 4096,"Finished","Done.") EXIT