nerdexam
Microsoft

98-372 · Question #83

Which of the following code segments is the most efficient way to rename a file from "File1.txt" to "File2.txt"?

The correct answer is B. File.Move("File1.txt", "File2.txt"). You use the static System.IO.File.Move method to rename files. The File.Move method is used to move a given file to a new location, providing the option to give a new file name. Answer: C is incorrect. The code segment will rename the file from "File1.txt" to "File2.txt but it…

Understanding .NET Framework Concepts

Question

Which of the following code segments is the most efficient way to rename a file from "File1.txt" to "File2.txt"?

Options

  • AFile.Replace("File1.txt", "File2.txt");
  • BFile.Move("File1.txt", "File2.txt");
  • CFile.Copy("File1.txt", "File2.txt");
  • DFile.Rename("File1.txt", "File2.txt");

How the community answered

(39 responses)
  • A
    5% (2)
  • B
    85% (33)
  • C
    8% (3)
  • D
    3% (1)

Explanation

You use the static System.IO.File.Move method to rename files. The File.Move method is used to move a given file to a new location, providing the option to give a new file name. Answer: C is incorrect. The code segment will rename the file from "File1.txt" to "File2.txt but it is not the most efficient way to rename the file. Answer: D is incorrect. There is no such method as File.Rename in the File class. Answer: A is incorrect. The File.Replace method is used to copy a file while overwriting the destination file. It does not rename files.

Topics

#File class#File.Move#file operations#System.IO

Community Discussion

No community discussion yet for this question.

Full 98-372 Practice