DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: AutoHotkey how to allow multiple inputs?  (Read 7,430 times)

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
AutoHotkey how to allow multiple inputs?
« on: April 30, 2007, 09:41 AM »
I've created an AHK script that takes multiple folders and copies all files inside to a destination folder, making a flattened copy as it were. At the moment I specifiy the folders in the script but to make the script more general I would like to allow the user to specifiy an 'unknown' amount of input folders and one output folder.

What would be the way to go? I could create an ini file but am not sure how to read in unknown amount of keys? I've never created an interface like that either.

code below
Code
;
; AutoHotkey Version: 1.0
; Language:       English
; Platform:       Win XP / Vista Tested
; Author:         justice <>
;
; Script Function:
;	Copies photos from multiple folders without subfolders into 1 target folder
;

#NoEnv
SendMode Input
#SingleInstance,Force
Menu, Tray, Icon, Shell32.dll, 174 
SetBatchLines, -1  ; Make the operation run at maximum speed.
CopyDest = c:\temp
NewFilesCopied = 0


; Example: A moving progress bar overlayed on a background image.

Gui, Color, White
Gui, Add, Picture, x0 y0 h350 w450, %A_WinDir%\system32\ntimage.gif ;doesn't exist in vista
gui, font, s16, Arial
Gui, Add, Text,BackgroundTrans x10 y10, PhotoUpdate
gui, font, s9, Arial
Gui, Add, Text, BackgroundTrans, Copying updated photos into `n%CopyDest%.

Gui, Add, Progress, vMyProgress x10 w430
Gui, Add, Text, vMyText wp  ; wp means "use width of previous".
Gui, Add, Picture, w140 h170 x155 y90 BackgroundTrans vMyPic,
Gui, Show

IfNotExist, %CopyDest%
	FileCreateDir, %CopyDest%

CopySourcePattern = d:\temp\01\*.jpg
GoSub, CopyIfNewer
CopySourcePattern = d:\temp\02\*.jpg
GoSub, CopyIfNewer
Sleep, 10000
ExitApp


; Example #5: Copy only the source files that are newer than their counterparts
; in the destination:
CopyIfNewer:
timesCalled += 1
GuiControl,, MyText, %timesCalled% (%NewFilesCopied%) - Reading %CopySourcePattern%...
i = 1
; Caller has set the variables CopySourcePattern and CopyDest for us.
Loop, %CopySourcePattern%,0,1
{
	Sleep, 10
	if i > 100
	{
		i = 1
	}
	GuiControl,, MyProgress, %i%
	i +=1
	copy_it = n
	StringReplace, FileNoSpaces, A_LoopFileName, %A_Space%,, All ;Take out spaces
	IfNotExist, %CopyDest%\%FileNoSpaces%  ; Always copy if target file doesn't yet exist.
		copy_it = y
	else
	{
		; File exists
		FileGetTime, time, %CopyDest%\%FileNoSpaces%
		EnvSub, time, %A_LoopFileTimeModified%, seconds  ; Subtract the source file's time from the destination's.
	
		if time < 0  ; Source file is newer than destination file.
			copy_it = y
	}
	if copy_it = y
	{
		NewFilesCopied += 1
		GuiControl,, MyPic, %A_LoopFileFullPath%
		GuiControl,, MyText, %A_LoopFileFullPath%
		FileCopy, %A_LoopFileFullPath%, %CopyDest%\%FileNoSpaces%, 1   ; Copy with overwrite=yes
		if ErrorLevel
			MsgBox, Could not copy "%A_LoopFileFullPath%" to "%CopyDest%\%FileNoSpaces%".
	}
}
GuiControl,, MyProgress, 100
GuiControl,, MyText, %timesCalled% (%NewFilesCopied%) - Finished copying %CopySourcePattern%.
Return

GuiClose:
ExitApp
« Last Edit: April 30, 2007, 09:54 AM by justice »

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: AutoHotkey how to allow multiple inputs?
« Reply #1 on: April 30, 2007, 02:02 PM »
I'd go for a .ini file in which you'd declare the number of elements to read. Here's how i did it for GridMove:

Spoiler (click to show/hide)
Code
[Groups]

  NumberOfGroups = 3

[1]
  TriggerTop    = [Monitor1Top]
  TriggerRight  = [Monitor1Left] + [Monitor1Width]  /2
  TriggerBottom = [Monitor1Top]  + [Monitor1Height] /2
  TriggerLeft   = [Monitor1Left]
  GridTop       = [Monitor1Top]
  GridRight     = [Monitor1Left] + [Monitor1Width]  /2
  GridBottom    = [Monitor1Top]  + [Monitor1Height] /2
  GridLeft      = [Monitor1Left]

[2]

  TriggerTop    = [Monitor1Top]
  TriggerRight  = [Monitor1Right]
  TriggerBottom = [Monitor1Top]  + [Monitor1Height] /2
  TriggerLeft   = [Monitor1Left] + [Monitor1Width]  /2
  GridTop       = [Monitor1Top]
  GridRight     = [Monitor1Right]
  GridBottom    = [Monitor1Top]  + [Monitor1Height] /2
  GridLeft      = [Monitor1Left] + [Monitor1Width]  /2

[3]

  TriggerTop    = [Monitor1Top]  + [Monitor1Height] /2 + 0.1
  TriggerRight  = [Monitor1Left] + [Monitor1Width]  /2
  TriggerBottom = [Monitor1Bottom]
  TriggerLeft   = [Monitor1Left]
  GridTop       = [Monitor1Top]  + [Monitor1Height] /2 + 0.1
  GridRight     = [Monitor1Left] + [Monitor1Width]  /2
  GridBottom    = [Monitor1Bottom]
  GridLeft      = [Monitor1Left]

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: AutoHotkey how to allow multiple inputs?
« Reply #2 on: May 01, 2007, 10:25 AM »
Thanks for that. After consideration I have decided to recreate the program as a commandline program, it makes it more flexible. However I  have a problem displaying the results.

I am appending statuses to stdout. I know Autohotkey cannot display the stdout by itself:
http://www.autohotkey.com/docs/commands/_ErrorStdOut.htm

Currently I have copied over cat.exe from GNUutils for windows and type this:
Code
level.exe |cat
However it would be good if I could use the one file to make it more portable.


I've attached a first version of my Level app and a screenshot. See what you think.


« Last Edit: May 01, 2007, 11:04 AM by justice »

Original address: https://www.donationcoder.com/forum/index.php?topic=8301.0