Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:16:33+00:00 2026-05-28T18:16:33+00:00

Beginner programmer here….hope it makes sense :) I have created a console app that

  • 0

Beginner programmer here….hope it makes sense 🙂

I have created a console app that I need to run in the background and watch a directory for any changes/rename events. I have used the FileWatcher class and have added the event handlers as so:

    watcher.Changed += new FileSystemEventHandler(OnChanged);
    watcher.Created += new FileSystemEventHandler(OnChanged);
    watcher.Deleted += new FileSystemEventHandler(OnChanged);
    watcher.Renamed += new RenamedEventHandler(OnRenamed);

and defined the handlers then below like so:

private static void OnChanged(object source, FileSystemEventArgs e)
{
    //specify what is done when a file is changed, created or deleted
    Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
    //specify what is done when a file is renamed 
    Console.WriteLine("File {0} renamed to {1}", e.OldFullPath, e.FullPath);

I would like to be able to add in some code that dumps any files that have changed/renamed into another local directory but I dont know where to start. At the minute the console is writing back the Fullpath to me but ideally I would like it to copy that into another folder

Thanks Guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:16:34+00:00Added an answer on May 28, 2026 at 6:16 pm

    You can use string destination = Path.Combine(localDirectory, e.Name); to create the destination path and File.Copy(e.FullPath, destination); actually copies the file.

    Note that a process may still be writing to the file when you get the Changed event, so you may get an exception or copy half-processed data. Also you should think about what to do if the file already exists in your local directory (notice the File.Copy(string, string, bool overwrite) overload).

    Also make sure you check if the changed item is a file and not a directory (for instance, by using File.Exists(e.FullPath).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner programmer here. So bear with me. I have a simple python program. print
I am a beginner programmer that have never used anything other than what's included
I am a beginner directshow programmer I am trying to make WPF App that
I am a beginner programmer, using python on Mac. I created a function as
I'm a beginner level programmer trying to make a game app for the iphone
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
I like to think that recently I have moved from complete beginner to beginner.
I'm re-inventing the wheel here, but as I'm a beginner programmer I'm curious as
I am a beginner programmer. I have a limited knowledge of javascript, but I
Hey everybody ! I am a beginner programmer and need some help with pointers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.