AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Run script when file added to a directory

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Noobee
Guest





PostPosted: Tue Nov 13, 2007 5:26 am    Post subject: Run script when file added to a directory Reply with quote

I need a script that will watch a certain directory and then run a script when a file is added to the directory. Can this be accomplished? Can ahk scripts run other ahk scripts in this manner?

Thanks in advanced!
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Tue Nov 13, 2007 5:37 am    Post subject: Reply with quote

http://www.autohotkey.com/forum/viewtopic.php?t=22862

Yes, scripts can run other scripts - see the Run command
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
NooBee
Guest





PostPosted: Tue Nov 13, 2007 2:04 pm    Post subject: re: Run script when file added to a directory Reply with quote

I was able to run the referenced script but I am not yet proficent enough to modify the script to suit my needs. I get lost in the loops. Embarassed

Does anyone else have a simpler example?
Back to top
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Tue Nov 13, 2007 6:48 pm    Post subject: Reply with quote

I don't know if there is a way to be notified when a file is added to a directory, but you could create your own monitoring of the directory.
Code:
#NoEnv
PreviousFiles := GetFiles()
SetTimer, CheckFiles, 1000
return

CheckFiles:
   Files := GetFiles()
   if (Files != PreviousFiles)
      Run, Script.ahk
   PreviousFiles := Files
   return

GetFiles() {
   files := ""
   Loop, C:\
      files .= A_LoopFileName
   return files
}
Back to top
View user's profile Send private message
NooBee
Guest





PostPosted: Wed Nov 14, 2007 4:24 am    Post subject: Reply with quote

I still don't get it I have added a beep to the GetFiles check so I know the code enters this point but files do not appear to be concatenated to the files="" because I don't get a beep when Files != PreviousFiles

Thanks for your patience

Code:

#NoEnv
#Persistent
PreviousFiles := GetFiles()
SetTimer, CheckFiles, 2000
return

CheckFiles:
   Files := GetFiles()
   if (Files != PreviousFiles)
   {
      SoundBeep, 750, 500
      ;Run, C:\ok.ahk
   }
   PreviousFiles := Files
   return

GetFiles() {
files := ""
   Loop, C:\WatchFolder
      files .= A_LoopFileName
   return files
}
Embarassed
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Wed Nov 14, 2007 4:35 am    Post subject: Reply with quote

time to learn some debugging tools such as msgbox, listvars, listlines, pause, OutputDebug, etc.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group