0
0
C Sharp (C#)programming~5 mins

File paths and Directory operations in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a file path in C#?
A file path is a string that shows the location of a file or folder on your computer. It tells the program where to find or save files.
Click to reveal answer
beginner
How do you combine parts of a file path safely in C#?
Use Path.Combine() method. It joins parts of a path with the correct separator for your system, avoiding errors.
Click to reveal answer
beginner
What does Directory.CreateDirectory() do?
It creates a new folder (directory) at the specified path. If the folder already exists, it does nothing and does not throw an error.
Click to reveal answer
beginner
How can you check if a file exists in C#?
Use File.Exists(path). It returns true if the file is there, otherwise false.
Click to reveal answer
intermediate
What is the difference between Directory.GetFiles() and Directory.GetDirectories()?
Directory.GetFiles() returns a list of files in a folder. Directory.GetDirectories() returns a list of subfolders inside a folder.
Click to reveal answer
Which method safely joins multiple parts of a file path in C#?
ADirectory.Merge()
BString.Concat()
CFile.Join()
DPath.Combine()
What does Directory.CreateDirectory() do if the folder already exists?
ADoes nothing and continues
BDeletes the folder
CThrows an error
DRenames the folder
How do you check if a file exists at a given path?
ADirectory.Exists(path)
BFile.Exists(path)
CFile.Check(path)
DPath.Exists(path)
Which method lists all files inside a directory?
ADirectory.GetDirectories()
BFile.List()
CDirectory.GetFiles()
DPath.GetFiles()
What is the correct way to get the file name from a full path?
APath.GetFileName()
BFile.GetName()
CDirectory.GetName()
DPath.GetDirectoryName()
Explain how to create a new directory and check if it exists in C#.
Think about methods to create and verify folders.
You got /3 concepts.
    Describe how to safely build a file path from folder and file name parts.
    Focus on combining path parts without errors.
    You got /3 concepts.