nerdexam
Microsoft

98-372 · Question #107

Allen is creating an application using .NET Framework 4.0. He needs to provide static methods for creating, moving, and enumerating through directories and subdirectories? Which class will he use?

The correct answer is B. Directory. The Directory class represents static methods for creating, moving, and enumerating by using directories and sub-directories. It is used for usual operations, such as copying, moving, renaming, creating, and deleting directories. The Directory class can also be used to get and…

Understanding Namespaces and Classes

Question

Allen is creating an application using .NET Framework 4.0. He needs to provide static methods for creating, moving, and enumerating through directories and subdirectories? Which class will he use?

Options

  • ADirectoryInfo
  • BDirectory
  • CFile
  • DFileInfo

How the community answered

(34 responses)
  • A
    3% (1)
  • B
    71% (24)
  • C
    18% (6)
  • D
    9% (3)

Explanation

The Directory class represents static methods for creating, moving, and enumerating by using directories and sub-directories. It is used for usual operations, such as copying, moving, renaming, creating, and deleting directories. The Directory class can also be used to get and set DateTime information associated to the creation, access, and writing of a directory. The Directory class cannot be inherited. Some members of the Directory class accept a path; the path can pass on to a file/directory. The given path can also pass on to a relative path or a Universal Naming Convention (UNC) path for a server as well as share name. For example, all of the following are "c:\MyDir" in C#, or "c:\MyDir" in Visual Basic. "MyDir\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic. "\\MyServer\MyShare" in C#, or "\MyServer\MyShare" in Visual Basic. Answer: C is incorrect. The File class is an utility class that is used to provide static methods to create, copy, delete, move, and open files. It is used to provide support in the creation of FileStream objects. It can also be used to get and set file attributes or DateTime information related to the creation, access, and writing of a file. It is more efficient to use the methods of the File class when only one task is to be performed. All methods of the File class require a specified path to the file that is to be manipulated. Answer: D is incorrect. The FileInfo class is an informational class that is used to provide instance methods to create, copy, delete, move, and open files. It is used to provide support in the creation of FileStream objects. Most of the FileInfo methods return other I/O types in case of creating or opening files. You can use these other types to further manipulate a file. It is better to use the instance method of the FileInfo class when an object is to be reused several times. The methods of the FileInfo class do not require any specified path to the file. Answer: A is incorrect. The DirectoryInfo class is used to provide methods for creating, moving, and enumerating through directories and subdirectories. This class can be used for common operations such as creating, copying, moving, renaming, and deleting directories. If an object is going to be used several times, consider using the methods of the DirectoryInfo class because a security check will not always be necessary.

Topics

#Directory class#System.IO#static methods#file system

Community Discussion

No community discussion yet for this question.

Full 98-372 Practice