O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.1. Copying, moving, and deleting files

When specifying the location of a file or directory, you can use an absolute path, a relative path, or a UNC share path. The following are acceptable paths to a file: [4]

[4] I suggest using the @ string literal for path or file names so that the string appears neater. For example, instead of c:\\expt\\loveletter.txt, you can use @"c:\expt\loveletter.txt".

  • c:\\expt\\loveletter.txt

  • expt\\loveletter.txt

  • \\\\shareddrive\\loveletter.txt

Table 18.3 shows the methods to use for performing copying, moving, and deletion of files. Code examples are given later.

Table 18.3. Methods to use for performing common file operations
FunctionSystem.IO.FileInfoSystem.IO.File
Copying a fileCopyTo(string destination_path)Copy ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required