Solved

Watching a folder for file population

Posted on 2004-08-17
6
315 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now