pete1234 Posted July 18, 2008 Posted July 18, 2008 I'm looking to make a script that will watch an empty folder. Whenever a file enters the folder, I'd like the script to move it to another directory and timestamp it. The last part is obviously easy, but I'm not sure how to tackle the first part. Would I need to create a service or something along those lines? Thanks for any ideas.
BrettF Posted July 18, 2008 Posted July 18, 2008 I'm looking to make a script that will watch an empty folder. Whenever a file enters the folder, I'd like the script to move it to another directory and timestamp it. The last part is obviously easy, but I'm not sure how to tackle the first part. Would I need to create a service or something along those lines? Thanks for any ideas.Have a look at FileFindFirstFile (). Call that in a loop, and just test what it returns. "Failure: Returns -1 if error occurs. If the Folder is empty the @error is set to 1. "In the loop, check it every 30 seconds or so, as not to chew up CPU.If you need any more help, post your code, and we'll see muttley Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
TehWhale Posted July 18, 2008 Posted July 18, 2008 (edited) #Include <File.au3> $Folder = "C:\Users\USER\Desktop\Watch Folder" $DestinationDir = "C:\Users\USER\Desktop\Other Folder" While 1 $FileArray = _FileListToArray($Folder) If Not $FileArray[0] = 0 Or $FileArray[0] = "0" Then FileMove($Folder&"\"&$FileArray[1], $DestinationDir&"\"&$FileArray[1]) ;timestamp it EndIf WEnd^^^ The above code is not tested. I will test it as soon as I can, this should give you a small example to go with.EDIT: @Bert, I was thinking FileFindFirstFile, but wasn't 100% sure. Edited July 18, 2008 by Alienware
BrettF Posted July 18, 2008 Posted July 18, 2008 #Include <File.au3> $Folder = "C:\Users\USER\Desktop\Watch Folder" $DestinationDir = "C:\Users\USER\Desktop\Other Folder" While 1 $FileArray = _FileListToArray($Folder) If Not $FileArray[0] = 0 Or $FileArray[0] = "0" Then WinMove($Folder&"\"&$FileArray[1], $DestinationDir&"\"&$FileArray[1]) ;timestamp it EndIf WEnd ^^^ The above code is not tested. I will test it as soon as I can, this should give you a small example to go with.You have got to be joking. Since when did WinMove move files and folders? Something like this would work, still untested. You said you knew what to do with the file move and timestamp, so I just put a message box there... muttley $watching = "C:\Watching\*.*" $moving = "C:\Move\Me\Here\" $timetowatch = 30 * 1000 $timestamp = TimerInit() While 1 If TimerDiff($timestamp) >= $timetowatch Then $check = FileFindFirstFile($watching) If $check <> -1 Then While 1 $file = FileFindNextFile($check) If @error Then ExitLoop MsgBox(4096, "File:", $file) WEnd EndIf $timestamp = TimerInit() EndIf Sleep (20) WEnd Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
TehWhale Posted July 18, 2008 Posted July 18, 2008 You have got to be joking. Since when did WinMove move files and folders? Something like this would work, still untested. You said you knew what to do with the file move and timestamp, so I just put a message box there... muttley $watching = "C:\Watching\*.*" $moving = "C:\Move\Me\Here\" $timetowatch = 30 * 1000 $timestamp = TimerInit() While 1 If TimerDiff($timestamp) >= $timetowatch Then $check = FileFindFirstFile($watching) If $check <> -1 Then While 1 $file = FileFindNextFile($check) If @error Then ExitLoop MsgBox(4096, "File:", $file) WEnd EndIf $timestamp = TimerInit() EndIf Sleep (20) WEndYeah, oops, I meant FileMove()
pete1234 Posted July 18, 2008 Author Posted July 18, 2008 Boy, that was quick! Thanks for the replies, I will do some testing later tonight or tomorrow and report back.
FreeFry Posted July 19, 2008 Posted July 19, 2008 Also, if he searches some in the forum, there's a WMI method, to detect file related actions, which he could use, then compare the path to the file in question, and see if it matches his path, then take action from there(this would be my preferred method of approach(even tho it's a lil bit advanced)). muttley
pete1234 Posted July 19, 2008 Author Posted July 19, 2008 ^ I saw a few of the file monitoring examples which I believe you are referring to. They look pretty cool, but my knowledge of AutoIt is not that advanced yet.Anyways, this is what I came up with in regards to the script.
rasim Posted July 19, 2008 Posted July 19, 2008 If DirGetSize("c:\Folder") > 0 Then MsgBox(0, "", "Not empty")
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now