waiting for file creation

Posted on 2009-02-24
Last Modified: 2013-11-26
I've to waiting for a file in a directory.
I explain better:
my program has to waiting that a file will be created in a directory,
so my program have to continue.
How can I do it in without Timer object?
and without the code below witch fill all the CPU?

while filename<>""


end while

Open in new window

Question by:bobdylan75
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Your code snippet doesn't tell us which environment you are actually working in...

    You using classic VB6 (or below) or VB.Net?  (you have multiple zones selected)

    Author Comment

    if you read slowly, you note that in the 2nd line from the bottom..
    I wrote "how can I do it in"
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Haha...gotcha.  =)

    You're looking for the FileSystemWatcher component then:

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    LVL 85

    Accepted Solution

    The below code and image show how to be notified when "c:\someFile.txt" is created:
    Public Class Form1
        Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
            MessageBox.Show("c:\someFile.txt Created!")
        End Sub
    End Class

    Open in new window


    Author Closing Comment

    Wow! Very interesting! thank you very much

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    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…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    745 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

    13 Experts available now in Live!

    Get 1:1 Help Now