Moving contents of a file

I have a program that watches a folder and when a file is dropped into that file it executes some code on the file then moves it to another file. The problem I am having is I dont know how to select the new file that was just moved into the folder thats being watched. My question is.

How can I select a file (or all the files, since their will only be one at a time) in the folder without knowing the files name, and be able to retrieve the name of the new file


Thanks


Answer this question

Moving contents of a file

  • jwennstrom

    Worked great thanks alot.


  • Phil Winder

    string[] files = System.IO.Directory.GetFiles(@"c:\FolderName");

    for (int i=0; i<files.Length; i++)
        Console.WriteLine(filesIdea);



  • Akin

    If your using a filesystemwatcher control:

    private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)

    {

    FileInfo f = new FileInfo(e.FullPath);

    }



  • Jason88

    I tried both code examples and I found that when you add more then one file at once to the folder being watched the e.FullPath only executes the first file and the

    string[] files = System.IO.Directory.GetFiles(@"c:\FolderName");

    for (int i=0; i<files.Length; i++)
        Console.WriteLine(files);

    Executes all the files added correctly.

     

    But they both worked for dropping one file at a time into the watched folder.

     

    Thanks guys



  • Moving contents of a file