c# - When I copy a file I get The process cannot access the file "..." because it is being used by another process -


i know easy 1 guys. new @ , know there probly program want learn.

my program copy files 1 location another, depending on age of file. when file going copied error. here 3 classes.

//find.cs  using system; using system.io; using system.collections;  namespace findold {     class find     {         static void main(string[] args)         {             console.write("please select option use: [c]opy, [m]ove, [d]elete : ");             string type = convert.tostring(console.readline());              console.write("what source path: ");             directoryinfo source = new directoryinfo(console.readline());              console.write("what destination path: ");             string destination = console.readline();              console.write("files of age want manage: ");             int32 months  = convert.toint32(console.readline());               string rootpath = convert.tostring(source.parent);             string newdest = path.combine(destination, rootpath);              if (type.toupper() == "c")                 copy.copyfolder(convert.tostring(source), newdest, type, months);              //if (type.toupper() == "m")               //  move.movefolder(source, newdest, type, months);              console.writeline("all done!");             console.readline();          } // end static main     } // end find class } // end findold namespace  //copy.cs  using system; using system.io;  class copy {     static public void copyfolder(string sourcefolder, string destfolder, string type, int32 past)     {          string[] files = directory.getfiles(sourcefolder);          foreach (string f in files)         {             string name = f;             string dest = path.combine(destfolder, name);              if (compare.timestamp(f, past) == true)             {                 if (!directory.exists(destfolder))                     directory.createdirectory(destfolder);                  file.copy(f, dest, true);             }              console.writeline(f);         }          string[] folders = directory.getdirectories( sourcefolder);          foreach (string folder in folders)         {             string name = path.getfilename(folder);             string dest = path.combine(convert.tostring(destfolder), name);              copyfolder(folder, dest, type, past);         }     } // end copyfolder method  }  //compare.cs  using system; using system.io;  class compare {     public static boolean timestamp(string file, int32 back)     {             fileinfo fi = new fileinfo(file);              if (fi.lastwritetime < datetime.now.addmonths(back))             {                 console.writeline("{0} written on {1}", fi.fullname, fi.lastwritetime);                 return true;             }              return false;     }  } 

each 1 of these seperate files. not sure why not working correctly. bombs after comes compare , ask perform copy. help


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -