Solved

Watching a folder for file population

Posted on 2004-08-17
6
317 Views
Last Modified: 2010-05-02
Hello all, I have a rather tricky VB problem I have not been able to solve so far.
I need to write a function that will "watch" an error folder for file population.  If a file jumps into the error folder, I need to perform a series of operations (i.e. copy to another directory, rename, strip extension, ect. ) on the said file and delete it from the error folder in the end.  The problem with this is the file that appears in the error folder is not always the same name.  depending on the nature of the error, a range of different files can potentially appear.  In addition, it is possible for more than one file to populate in this location at a time, it is not uncommon to have seven or more such files appear at once.  I need some sort of way to constantly scan the folder to detect for errors even though my operations will only handle one at a time.

I tried doing this with a simple timer control but am having difficutly opening a folder and scanning for files without having the exact name.  Any suggestions?
0
Comment
Question by:gwosgood
6 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 11822297
Maybe this example can help:

http://www.thescarms.com/vbasic/FolderSpy.asp
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 11822816
That looks pretty cool.  I think I'll download that for future use.  Thanks!
0
 
LVL 15

Accepted Solution

by:
unknown_routine earned 500 total points
ID: 11822826
Hi


You can achieve this using FilesySystemObject


Add a reference to "microsoft scripting runtime"  to your project

then use this sample code:

Private Sub Form_Load()

    Dim fs As New FileSystemObject
   
    Dim fo As Folder
   
    Set fo = fs.GetFolder("C:\Myfloder")    '<===Change this to the specific folder name
   
    Dim Fi As File
   
    For Each Fi In fo.Files
   
         MsgBox " Name=" & Fi.Name & " " & vbCrLf & "Date created=" & Fi.DateCreated
   
    Next

End Sub



In the above code Fi(file object) has a lots ofother useful properties whcih you can use them.


More questions, please  Ask,


Regards.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Expert Comment

by:Steve Sirica
ID: 11822889
It's also alot easier now in VB.Net seeing that MS now sends a canned filewatch control along with.
0
 
LVL 2

Author Comment

by:gwosgood
ID: 11823375
Comment for "unknown_routine"  your solution appears to be very handy.  My only question is how to use.  Would I just tie it into a timer routine and check for files once every X seconds?
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 11823443
Exactly,

As far as your timer interval is bigger that 100 (1 tenth of a second)

it is healthy( usage of CPU is negligible).




Regards.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question