1. File System Intro Flashcards

1
Q

What should you check to see before creating a new directory via code?

A

Whether or not it exists already.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you check whether a directory exists?

A

By passing its path to the Exists static method of the Directory class.

eg. Directory.Exists(“/some/path”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a folder in C#?

A

By using the static CreateDirectory method of the Directory class and passing it the path to of the directory to be created.

eg. Directory.CreateDirectory(“/some/path”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you delete a folder in C#

A

By using the static Delete method of the Directory class and passing it the path of the directory to be deleted.

eg. Directory.Delete(“/some/path”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens if you try to delete a folder that has folders or files in it?

A

You get a System.IO.IOException saying “Directory not empty”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the optional second argument of the Directory.Delete method and what does it determine?

A

A boolean value named recursive that determines whether the contents of the folder should also be deleted if there is any.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you delete a folder and all its contents if there are any in C#?

A

By using the Directory.Delete method and passing the folder path and true respectively as arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you move a folder and all its contents into a new folder?

A

By using the Directory.Move method and passing the existing directory path and the new path respectively as arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly