Datei auswählen Fenster

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

aeran
Posts: 21
Joined: 13 Apr 2016, 09:06

Datei auswählen Fenster

13 Nov 2016, 15:09

Hallo, ich habe ein ganz einfaches Skript zum konvertieren von csv Dateien nach html Dateien. Dabei muss man die Ein- und Ausgabe Pfade per Hand eintippen. Es wäre aber viel schöner und einfacher, wenn so ein Datei Auswahl Fenster geben würde.
http://www.access-im-unternehmen.de/fil ... pic003.png
Würde mich auf ein Template oder fertig skript freuen.

Hier mein Code:

Code: Select all

#CommentFlag //

// Recommended for new scripts due to its superior speed and reliability.
SendMode Input   

// Setting Working Directory
SetWorkingDir %A_ScriptDir%  

// Gui Creation - Adding Text- and Edit-fields
Gui, Font, S28 CDefault, Arial
Gui, Add, Text, x15 y20 w400 h50, FROM PFAD
Gui, Add, Edit, x15 y60 w400 h50 vFrom, 

Gui, Add, Text, x15 y140 w400 h50, TO PFAD
Gui, Add, Edit, x15 y180 w400 h50 vTo,

Gui, Add, Button, x15 y280 w190 h50, Convert

// makes the GUI visible
Gui, Show, x200 y100 h450 w430, CSV to HTML v0.1

Return

// Cloesing the GUI
GuiClose:
	ExitApp

ButtonConvert:
	Gui, Submit, NoHide

	FileRead,Csv,%From%
	Html:=Csv2Html(Csv)
	FileAppend,%Html%,%To%
	Run %To%
	Csv2Html(Csv,FeldTrenner=";")
	{
		HochKommas="
		StringReplace,Csv,Csv,%HochKommas%,,all
		StringReplace,Csv,Csv,`r,,all
		StringReplace,Csv,Csv,`n,</td></tr>`r`n<tr><td>,all		
		StringReplace,Html,Csv,%FeldTrenner%,</td><td>,all
		StringTrimRight,Html,Html,20
		Vor=<table border="1" width="100`%">`r`n<tr><td>
		Nach=</td></tr>`r`n</table>
		return Vor Html Nach
	}	

Return


Danke und einen schönen Abend
garry
Posts: 3772
Joined: 22 Dec 2013, 12:50

Re: Datei auswählen Fenster

13 Nov 2016, 17:09

hier nur ein GUI Beispiel
( erstellt lediglich ein ini-file , wo Source und Destination der gewählten Ordner gespeichert werden )

Code: Select all

;- test GUI
#Warn
SetWorkingDir, %A_ScriptDir%
Filename1=FileCOPY_2016
Gui,2: default
Gui,2:Color, Black
Gui,2:Color, ControlColor, Black
Gui,2:Font,,FixedSys
source1x:=""
dest1x:=""
fdd1:=""
fdd2:=""
fdd3:=""

RSSINI=%A_scriptdir%\%filename1%_INI.ini
ifnotexist,%rssini%
    {
    IniWrite,C:\test1  , %rssini% ,Source      , Source_PATH
    IniWrite,C:\test2  , %rssini% ,Destination , Destination_Path
    }
IniRead, source1x, %rssini% , Source      , Source_PATH
IniRead, dest1x, %rssini% , Destination , Destination_Path
Gui,2: Add, button,  x10   y10 h25 w100 gSource1, Source ...
Gui,2: Add, button,  x10   y40 h25 w100 gDest1  , DEST   ...
Gui,2: Add, Edit,    x130  y10 w800 vsource1x cGray readonly,%source1x%
Gui,2: Add, Edit,    x130  y40 w800 vdest1x cGray readonly,%dest1x%
Gui,2: Add, button,  x950  y10 h25 w80 gSource1a vSOURCEB,OPEN
Gui,2: Add, button,  x950  y40 h25 w80 gDest1a   vDESTB  ,OPEN
Gui,2: Add, Edit,    x130  y80 w800  cRed readonly vExtensions,
Gui,2: add, button,  x10   y80 h25  w80 gStartx vSt1,Start
Gui,2: Add, Text  ,  x130  y105 w800 cGray vtext1

Gui,2: Show,x100 y10 w1050 h170,%filename1%
ifnotexist,%source1x%
   {
   GuiControl,Disable,sourceb
   GuiControl,Disable,St1
   }
ifnotexist,%dest1x%
   {
   GuiControl,Disable,destb
   GuiControl,Disable,St1
   }
return
;-----------------------------

startx:
Extensions1 := "htm,html,txt"
Guicontrol,2: ,text1,TEST command missing
Guicontrol,2: ,extensions,%extensions1%
return

source1:
  ;---------- SOURCE select ----------------------
  FD1:=""
  FileSelectFolder,FD1,, 2, Pick up SOURCE folder
  if (fd1="")
     return
  Guicontrol,2: ,source1x,%fd1%
  GuiControl,Enable,sourceb
  gosub,save1
return
;------------------------------------------
dest1:
  ;--------- DESTINATION select ------------------
  FD2:=""
  FileSelectFolder,FD2,, 2, Pick up DESTINATION folder
  if (fd2="")
     return
  Guicontrol,2: ,dest1x,%fd2%
  GuiControl,Enable,destb
  gosub,save1
return

source1a:
Gui,2:submit,nohide
ifexist,%source1x%
    run,%source1x%
return
;------------------------
dest1a:
Gui,2:submit,nohide
ifexist,%dest1x%
    run,%dest1x%
return
;------------------------
2Guiclose:
Gui,2:submit,nohide
gosub,save1
exitapp
;-----------------------------
save1:
IniWrite,%source1x% , %rssini% ,Source      , Source_PATH
IniWrite,%dest1x%   , %rssini% ,Destination , Destination_Path
guicontrolget,source1x
guicontrolget,dest1x
ifexist,%source1x%
    fdd1:=1
ifexist,%dest1x%
    fdd2:=1
fdd3:=(fdd1+fdd2)
if (fdd3=2)
   GuiControl,Enable,ST1
return
;-----------------------------
aeran
Posts: 21
Joined: 13 Apr 2016, 09:06

Re: Datei auswählen Fenster

16 Nov 2016, 06:05

just me wrote:FileSelectFile :?:
Danke, genau das wollt ich :)

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 17 guests