Write mobile files when the practice found that directory.move can only be in the same drive to operate, so the Niang, but also really someone has encountered this situation, search for a man wrote a cross-letter mobile demo is very good to share, the original is as follows:
1 Public voidMoveDirectory (stringStrsourcedir,stringStrdestdir,BOOLBdelsource)2 {3 if(Directory.Exists (strsourcedir))4 {5 if(Directory.getdirectoryroot (strsourcedir) = =Directory.getdirectoryroot (strdestdir))6 {7 Directory.move (Strsourcedir, strdestdir);8 }9 ElseTen { One Try A { -CopyDirectory (NewDirectoryInfo (Strsourcedir),NewDirectoryInfo (Strdestdir)); - if(Bdelsource) Directory.delete (Strsourcedir,true); the } - Catch(Exception Subex) - { - ThrowSubex; + } - } + } A } at Private voidcopydirectory (DirectoryInfo disourcedir, DirectoryInfo didestdir) - { - if(!didestdir.exists) didestdir.create (); -fileinfo[] Fisrcfiles =disourcedir.getfiles (); - foreach(FileInfo Fisrcfileinchfisrcfiles) - { in Fisrcfile.copyto (Path.Combine (Didestdir.fullname, Fisrcfile.name)); - } todirectoryinfo[] Disrcdirectories =disourcedir.getdirectories (); + foreach(DirectoryInfo disrcdirectoryinchdisrcdirectories) - { theCopyDirectory (Disrcdirectory,NewDirectoryInfo (Path.Combine (didestdir.fullname, Disrcdirectory.name )); * } $ }Panax Notoginseng Private voidButton1_Click (Objectsender, EventArgs e) - { the //MoveFolder1 (); + stringSnowfile = System.Windows.Forms.Application.StartupPath +"\\seo"; A stringSnfile = Environment.SystemDirectory.Replace ("System32",""); theMoveDirectory (Snowfile, Snfile,true); +}
Simple code to make people suddenly enlightened, in fact, we can change the angle, he is to create a path to traverse the source address file copied to the destination address, and then delete the original file. This solves, the code is easy to understand!
C # cross-drive characters move files