Hi all!
I've just created the following program:
My problem now is that I want to have this program running all the time and when a file is created in the directory I want the program to automatically copy and rename the file.
Right now I can just rename and move the files one time, when the directory have files in it, I cant move the files there any more. I have no idea why, but maybe you guys can help me with this.
Thanks!
I've just created the following program:
Code:
using System; using System.IO; namespace FileRename { class MyClass { static void Main(string[] args) { try { DirectoryInfo mydir = new DirectoryInfo(@"C:\Users\alexander.axelsson\Documents\Affärssystemet\Scannade filer"); FileInfo[] a = mydir.GetFiles("*.txt"); int i = 0; string filepath; foreach (FileInfo fri in a) { filepath = @"C:\Users\alexander.axelsson\Documents\Scanner\test" + "pic" + i.ToString("D3") + ".txt"; fri.MoveTo(filepath); i++; } Console.WriteLine("Done"); } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } } } }
Right now I can just rename and move the files one time, when the directory have files in it, I cant move the files there any more. I have no idea why, but maybe you guys can help me with this.
Thanks!
Comment