Jump to content

FileOpen Select Files - Write txt file


 Share

Recommended Posts

Hello

i have created a small tool for selecting files and writing the results to a txt file:

I need to be able to select multiple files and write the results to vedlegg.txt in comma separated form like this:

vedlegg.txt:

c:\etc.txt,c:\somthing.exe,c:\program files\test\test.exe

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayIconHide", 1)
$mainGUI = GUICreate("Velg fil", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$FileOpenDialog_button = GUICtrlCreateButton('Velg fil', 40, 50, 50)
GUICtrlSetOnEvent($FileOpenDialog_button, "FileOpenDialog_button")
$Exit_button = GUICtrlCreateButton('Lukk', 90, 50, 50)
GUICtrlSetOnEvent($Exit_button, "CLOSEClicked")
GUISetState(@SW_SHOW)

While 1
  Sleep(500)
WEnd

Func FileOpenDialog_button()
    Local $Title = "Velg fil"
    Local $Filter = 'Alle filer' & Chr(0) & '.exe' & Chr(0) & Chr(0)
    Local $InitPath = 'C:'
    Local $InitializeWithFilename = ''
    Local $AutoAppendExtension = ''

    $Result = DllCall("Shell32.dll", _; dll mother
            "int", 'GetFileNameFromBrowse', _; returns array, [2] contains selected string
            'hwnd', $mainGUI, _; maingui to bind msgbox to (if any)
            'wstr', $InitializeWithFilename, _; filename to initialize function with (if any)
            'int', 255, _; max file string length
            'wstr', $InitPath, _; path to initially browse from
            'wstr', $AutoAppendExtension, _; makes dialog append a specific extension, no "." needed
            'wstr', $Filter, _; shows all (*.*) or specific (*.exe) files
            'wstr', $Title); title of dialog box
   
    FileWrite('u:\vedlegg.txt', $Result[2])
    sleep(1000)
    ProcessClose('file_open.exe')
EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Any ideas to solve this chalange?`, the original code cand be changed :)

Link to comment
Share on other sites

Give it a try...

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayIconHide", 1)
Global $mainGUI
$mainGUI = GUICreate("Velg fil", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$FileOpenDialog_button = GUICtrlCreateButton('Velg fil', 40, 50, 50)
GUICtrlSetOnEvent($FileOpenDialog_button, "FileOpenDialog_button")
$Exit_button = GUICtrlCreateButton('Lukk', 90, 50, 50)
GUICtrlSetOnEvent($Exit_button, "CLOSEClicked")
GUISetState(@SW_SHOW)

While 1
  Sleep(500)
WEnd

Func FileOpenDialog_button()
    Local $Title = "Velg fil"
    Local $Filter = 'Alle filer (*.exe)'
    Local $InitPath = 'C:'
    Local $ResultTemp = ''
   
    $Result = FileOpenDialog($Title, $InitPath, $Filter, 4, '', $mainGUI)
    If @error Then Return
    $Result = StringSplit($Result, '|')
    If IsArray($Result) Then
        If $Result[0] = 1 Then
            $ResultTemp = $Result[1]
        ElseIf $Result[0] > 1 Then
            For $x = 2 To $Result[0]
                $ResultTemp &= $Result[1] & '\' & $Result[$x] & ','
            Next
            $ResultTemp = StringTrimRight($ResultTemp, 1)
        EndIf
    Else
        Return
    EndIf   
    FileWrite('c:\vedlegg.txt', $ResultTemp & @CRLF)
    sleep(1000)
    ProcessClose('file_open.exe')
EndFunc

Func CLOSEClicked()
  If FileExists('c:\vedlegg.txt') Then ShellExecute('c:\vedlegg.txt', '', @WorkingDir)
  Exit
EndFunc
Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...