 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
bpmb
Joined: 13 Sep 2009 Posts: 30
|
Posted: Mon Oct 19, 2009 6:13 pm Post subject: Multiple inputs from user - too much code |
|
|
Hi there!
I made a script which backups certain folders and it's contents and assigned a nice hotkey to launch it, no problem so far.
However, my friends are now asking me to give them the ability to choose multiple source and destination folders and have them all backupped at once. Here's an example of the script:
| Code: | SetWorkingDir, %BrowseSource%
Loop, *.*, , 1
{
CopySourcePattern = %A_LoopFileLongPath%
CopyDest = %BrowseDest%
IfNotExist, %CopyDest%\%A_LoopFileDir%
FileCreateDir, %CopyDest%\%A_LoopFileDir%
GuiControl,, MyProgress, 25 ; Increase the current position to 25.
copy_it = n
IfNotExist, %CopyDest%\%A_LoopFileFullPath% ; Always copy if target file doesn't yet exist.
copy_it = y
else
GuiControl,, MyProgress, 50 ; Increase the current position to 50.
{
FileGetTime, time, %CopyDest%\%A_LoopFileName%
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
{
FileCopy, %A_LoopFileLongPath%, %CopyDest%\%A_LoopFileFullPath%, 1 ; Copy with overwrite=yes
if ErrorLevel
MsgBox, Could not copy "%A_LoopFileFullPath%" to "%CopyDest%\%A_LoopFileFullPath%".
}
GuiControl,, MyProgress, 100 ; Increase the current position to 100.
} |
I can, of course, add extra buttons, assign them the variable BrowseSource2 e.g. and copy and paste this example above again but change BrowseSource to BrowseSource2. This however seems a rather complicated way of doing things.
I'd like to be able to let the user choose for himself how many folders he wants to backup without me having to copy/ paste these lines over and over again..
BTW; BrowseSource is determined by a 'Select source' button in the main GUI which opens a FileSelectFolder who's output is stored in BrowseSource.
Thanks ahead! |
|
| Back to top |
|
 |
txquestor
Joined: 22 Aug 2009 Posts: 294
|
|
| Back to top |
|
 |
bpmb
Joined: 13 Sep 2009 Posts: 30
|
Posted: Mon Oct 19, 2009 6:53 pm Post subject: |
|
|
hi txquestor, thanks for the suggestions!
I know there are a lot of backup utilities already out there but I learned (and am still learning) SO much from writing my own I'd like to continue with my own one..
If only I knew how to give a user unlimited source and destination choices so he/ she can backup everything in 1 go..
For example, I'm not only programming scripts, I also make music in Cubase 5, edit pictures or movies in Adobe CS4 and have a lot of files in a lot of different places. This way, I could make a backup of ALL those files in 1 go to my NAS..
I wrote the script that it stores all the sources and destinations (stopped copy/ pasting after 2 ) in an INI file so the next time you use the Hotkey it asks you to backup the default folders and goes ahead after pressing Yes..
Thanks again! |
|
| Back to top |
|
 |
txquestor
Joined: 22 Aug 2009 Posts: 294
|
Posted: Mon Oct 19, 2009 8:37 pm Post subject: |
|
|
You also learn alot by dissecting other's scripts.
Especially if they already work.
All the functions you need to accomplish your own goal
are problably already discussed & written about.
Don't ignore that resource because you want to DO IT SELF.
My daughter used to say that when she was a baby.
Any how, one of the ways that I leaned besides experimenting with each command.
Was to take a snippet of code someone wrote and dissect it line by line
and write a comment next to it explaining how it works.
Then if I couldn't figure it out, I'd ask the forum.
Doing what you want is no small task with all the flexibility you want.
But go after it
Have Fun  _________________
"Man's quest for knowledge is an expanding series whose limit is infinity" |
|
| Back to top |
|
 |
functionalize it Guest
|
Posted: Tue Oct 20, 2009 8:50 am Post subject: |
|
|
| you need to learn how to use functions, tkae a look in the help file! |
|
| Back to top |
|
 |
Vifon
Joined: 22 Feb 2009 Posts: 47 Location: Poland
|
Posted: Tue Oct 20, 2009 9:13 am Post subject: |
|
|
| Maybe some parts of my ToDo program will help you - take a look. |
|
| Back to top |
|
 |
txquestor
Joined: 22 Aug 2009 Posts: 294
|
Posted: Tue Oct 20, 2009 6:29 pm Post subject: |
|
|
Hi Vifon,
I understand how your Backup example works.
I don't understand what your ToDo.ahk example has to do with backups.
As far as your users wanting the flexibility of adding files/folders of their choice to the auto backup all at once idea.
The commands FileSelectFolder, FileSelectFile, FileCopyDir, FileMoveDir, FileCopy & FileMove
all provide the method to collect files/folders & copymove them wherever you want to do your backup. Either store the locations in a file or variable.
I would suggest talking to your users and write a little specification of features.
Because without it I don't know how to code something or suggest an approach beyond what you already defined.
Example.
Is the backup location fixed or user choice?
As you can see, your approach to coding is very different depending on which method you chosose.
My philosophy is any time more than one person is involved.
Interview & write a specification and get everyone to agree on.
Otherwise, you run the risk of constantly changing the application.
This may cause a total different approach and you start from scratch again.
Another example is this forum.
You will see numerous times where someone started with an idea and
other forum users startied recommending features/changes.
Over a period of weeks or months it evolves into a finished program.
Is this what you want to do. Or start with a well defined approach,
code it. Review with users for final changes and you are done.
One is major the other is minor.
Good Luck,  _________________
"Man's quest for knowledge is an expanding series whose limit is infinity" |
|
| Back to top |
|
 |
Vifon
Joined: 22 Feb 2009 Posts: 47 Location: Poland
|
Posted: Tue Oct 20, 2009 9:29 pm Post subject: |
|
|
| txquestor wrote: | I understand how your Backup example works.
I don't understand what your ToDo.ahk example has to do with backups. | I didn't mean the backup part (I think it is unnecessary now but I'm too lazy to delete it). I meant that it has variable number of rows. I thought it would help. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|