Use system.IO namespace
FileInfo myfile = new FileInfo(@"H:\myphoto.jpg");
if (myfile.Exists)
{
myfile.CopyTo(@"H:\myphoto.bak",true );
myfile.MoveTo(@"H:\photos\photo.jpg");
}
- If the second parameter is true, the existing file will be replaced.
- If we specify an invalid path in MoveTo() it will throw DirectoryNotFoundException.
No comments:
Post a Comment