Monitoring a Folder for New Files

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Alex Silva

Monitoring a Folder for New Files

Post by Alex Silva » Tue Mar 25, 2003 5:52 am

I have a need to monitor a specific folder in my server, H:\Upload. I am trying to see if there is a way that the computer will [sound.wav] something if a new file is sitting in that directory, or maybe open the screen and ask me where I want to move it within the H: drive. Just different ideas.

I am using an FTP program at this time that [sounds.wav] when a user connects, sends a file, errors, etc. I am trying to use a ASP for web upload, which doesn't give me any of that. That is my reason for trying to see if there are some commands that you all can throw at me that might guide me somewhere.

Thanks in advance.

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Tue Mar 25, 2003 8:31 am

The only way I can think of would be to obtain a file listing every so often, and run a comparison.

There is the "GetFileList>" command, which could be used. There's also the FileSize and FileDate commands too. (You could use that to check if an existing file has been altered).

The simplest method would probably be to remember an array of the filename/filesize, then loop through with the new file list. You could see not only if any new files exist, but if any old files are missing.

If there are a large number of files in the directory, you may wish to have the interval be pretty large. I think windows has some internal method to have a specific directory 'monitored', and then windows informs your application when a change inside this directory occurs. As far as I know, there is no built-in method to take advantage of this from msched.

If you wanted to go silly, you could do something like this:
Have msched open an explorer window at your directory.
Let msched to a 'checksum' of a certain rectangle - example: an area covering the the part in explorer that says the number of files and/or total size. Then have msched re-evaluate that little rectangle every now and again.

Personally, I would go with the 'GetFileList' method.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Mar 25, 2003 3:49 pm

Hi,

Yes, use GetFileList and Separate which will give you a count of the files there. When count changes, you have a new file.
MJT Net Support
[email protected]

Guest

Post by Guest » Fri Apr 11, 2003 2:53 pm

I have NO clue what you guys are talking about. All I am trying to do is watch a folder called H:\Upload which is always empty. If a file is upload, then, of course the file will show in this directory, and what I am looking for is to open the H:\Upload screen and to play a WAV file that we have recorded "File Is In" type wav file.

Any help? Thanks in advance.

I don't even have any idea how to get this macro done. I have done several macros, but they have been more of the click here, send chr this, lah lah..

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Apr 11, 2003 4:28 pm

All you want to do is play a wav file when a new file is in the directory? I suspect that there is much more to be done when that file has arrived, but this does the basics. Try this.
GetFileList>H:\Upload\*.wav,result
If>%file_names_count%>0,NewFile,End

Label>NewFile
\\Move file to another folder so next count will be zero
MoveFile>h:\upload\*.wav,h:\upload\archive\*.wav
PlayWav>c:\path\fileisin.wav

Label>End
Hope this helps, good luck
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Guest

Post by Guest » Sat Apr 12, 2003 10:27 pm

I do thank you for giving me the idea. This is what I have done so far:
GetFileList>c:\upload\*.*,result
If>%result%>0,NewFile,End

Label>NewFile
PlayWav>c:\winnt\media\ringin.wav

Ask>Can the file be moved yet?,continue
If>continue=YES,move2dir
Goto>End

Label>move2dir
Input>dirnum,What Directory Number?
If>dirnum=9,Dir999

MoveFile>c:\upload\*.*,c:\customers\00000%dirnum%\*.*
Goto>End

Label>Dir999
MoveFile>c:\upload\*.*,c:\customers\99999999\*.*

Label>End
I noticed that on the help file under MoveFile it says that wildcards can be used, but it is not working. If I change the *.* on both (source and dest) on each line above to name.txt or whatever.ext, then it works. So, it seems like the wildcard option does not work. OR, I am doing something wrong, and I have NO clue! :(

I'll appreciate your help/answer to my above problem. I have also changed the drive letter to C: rather than H: as mentioned on my first line since I am not working on my network at this time, for testing purposes.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Apr 13, 2003 3:25 am

Looks good. You are on the right track.

I would strongly suggest moving the file immediately. If not, the count in the folder will always be >0 and you will not know when other files come in. It will always play the sound file even when no new files have arrived. Move it immediadely to the archive folder. Then when you ask about moving it, move it from the archive folder vs. the original receiving folder.

If you don't want to move the file, then you will have to take a more complex approach of storing results in a file each time you check and then comparing current results with previous results. By moving it to an archive folder immediately, you can still delay actions until later, but have the ability to do simple instant checks for new files.

Also, since you are deferring movement the issue of wild cards is probably not significant. You want to get the actual filename by reading %result% and using the actual filename in the subsequent file move commands. If you use wild cards with deferred actions, then you may end up moving files you don't know have arrived yet.

Again, just a few thoughts that crossed my mind. Good luck.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Sun Apr 13, 2003 8:32 am

I noticed that on the help file under MoveFile it says that wildcards can be used, but it is not working. If I change the *.* on both (source and dest) on each line above to name.txt or whatever.ext, then it works. So, it seems like the wildcard option does not work. OR, I am doing something wrong, and I have NO clue!
If you want to use a wildcard for the 'source', then don't include a filename part for the 'destination'.
For example, try something like this:
MoveFile>c:\upload\*.*,c:\customers\00000%dirnum%\

Guest

Post by Guest » Sun Apr 13, 2003 3:40 pm

bob hansen wrote: I would strongly suggest moving the file immediately. If not, the count in the folder will always be >0 and you will not know when other files come in. It will always play the sound file even when no new files have arrived. Move it immediadely to the archive folder. Then when you ask about moving it, move it from the archive folder vs. the original receiving folder.

If you don't want to move the file, then you will have to take a more complex approach of storing results in a file each time you check and then comparing current results with previous results. By moving it to an archive folder immediately, you can still delay actions until later, but have the ability to do simple instant checks for new files.

Also, since you are deferring movement the issue of wild cards is probably not significant. You want to get the actual filename by reading %result% and using the actual filename in the subsequent file move commands. If you use wild cards with deferred actions, then you may end up moving files you don't know have arrived yet.
Actually, I ran into an issue, which is the software that I am using, a webupload.asp, when my customer is uploading, of course, the file is been stored into the C:\Upload directory, what is happening is that the macro is seen that there is a new file there. So, that was the reason for me to make it stop and ask me were to move it, otherwise I was going to end up with UNCOMPLETE uploads, which is what already happened to me. So, this way we have the time to stop and check the webupload program which gives me a status bar to see if we can move the file or not. Then the other issue that I was running into was that since I was moving *.*, if another customer started uploading at the same time, then even though we waited for the 1st file to finish, we can't continue, since there is a 2nd file been uploaded, not only that, both files will be moved the 1 customer, which my intentions are to move them to separate dir's since they are from 2 separate customers.

Now, you mentioned about the %result% list. Does the %result% keep the filename store so I can only move one file at a time? Or which ever file I decide to move? The only thing from stopping me to finalize using this would be the issues above. I have to, somehow, be able to select a specific file, once finished, to move it to the dirnum that I assigned that customer, and leave the other files be. And on the next round, 1 min increment, the macro will ring again and let us know that there is another file and then choose the next file once it is finished.

About you mentioning the ring.wav, it only rings when there is a new file in the dir, If>%result%>0,NewFile,End takes me to END, so I don't know what you mean that I have it rining everytime if file or not.

Guest

Post by Guest » Sun Apr 13, 2003 3:41 pm

Captive wrote:
I noticed that on the help file under MoveFile it says that wildcards can be used, but it is not working. If I change the *.* on both (source and dest) on each line above to name.txt or whatever.ext, then it works. So, it seems like the wildcard option does not work. OR, I am doing something wrong, and I have NO clue!
If you want to use a wildcard for the 'source', then don't include a filename part for the 'destination'.
For example, try something like this:
MoveFile>c:\upload\*.*,c:\customers\00000%dirnum%\
Thanks, that worked. I guess I tried just about every way of doing it, except removing it from the last line.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Apr 13, 2003 4:38 pm

Now, you mentioned about the %result% list. Does the %result% keep the filename store so I can only move one file at a time?

Yes, %result% will have all the file names. Use Separate to put the filenames into a file. Use ReadLn to process each filename in the folder. Once you have the filename you can get its size, date, etc. Check conditions with an If to determine what other prompts you might want to see.

See the Help sections on GetFileList, Separate, ReadLn and If. Using a combination of these commands you can make a loop to prompt you for actions on every file in the folder or just files that meet certain conditions.
=========================
About you mentioning the ring.wav, it only rings when there is a new file in the dir, If>%result%>0,NewFile,End takes me to END, so I don't know what you mean that I have it rining everytime if file or not.

Oops, my mistake. I was thinking of the original version I sent you that used the count, not the result. I forgot that you changed it to %result%. Sorry about that..... :oops:
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts