Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 02, 2016, 08:31:11 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AutoHotkey how to allow multiple inputs?  (Read 2941 times)

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
AutoHotkey how to allow multiple inputs?
« on: April 30, 2007, 04:41:48 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
;
; 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, 04:54:43 AM by justice »

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: AutoHotkey how to allow multiple inputs?
« Reply #1 on: April 30, 2007, 09:02:41 AM »
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
[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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: AutoHotkey how to allow multiple inputs?
« Reply #2 on: May 01, 2007, 05:25:00 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.autohotke...nds/_ErrorStdOut.htm

Currently I have copied over cat.exe from GNUutils for windows and type this:
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, 06:04:18 AM by justice »