Challenge - 5 Problems
File Path Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this MATLAB code using fullfile?
Consider the following MATLAB code that constructs a file path. What will be the output printed?
MATLAB
folder = 'data'; file = 'results.txt'; filepath = fullfile(folder, file); disp(filepath);
Attempts:
2 left
💡 Hint
fullfile joins parts of a path using the correct file separator for your system.
✗ Incorrect
The fullfile function joins folder and file using the system's file separator. On Windows, it uses '\' so the output is 'data\results.txt'.
❓ Predict Output
intermediate2:00remaining
What does fileparts return for this path?
Given the MATLAB code below, what are the outputs of [folder, name, ext]?
MATLAB
[folder, name, ext] = fileparts('C:\Users\user\Documents\report.pdf'); fprintf('%s|%s|%s', folder, name, ext);
Attempts:
2 left
💡 Hint
fileparts splits the path into folder, filename without extension, and extension.
✗ Incorrect
fileparts returns the folder path, the file name without extension, and the extension including the dot. So folder is 'C:\Users\user\Documents', name is 'report', ext is '.pdf'.
🔧 Debug
advanced2:00remaining
Why does this code fail to create a valid path?
This MATLAB code tries to create a file path but produces an error. What is the cause?
MATLAB
folder = 'C:\Data'; file = 'output.txt'; filepath = [folder '\' file]; disp(filepath);
Attempts:
2 left
💡 Hint
Check how backslashes are used in strings in MATLAB.
✗ Incorrect
In MATLAB, backslash is an escape character. To include a literal backslash, you must use two backslashes \\. The code uses a single backslash '\' which is invalid.
❓ Predict Output
advanced2:00remaining
What is the output of this code using filesep?
What will this MATLAB code display?
MATLAB
folder = 'myfolder'; file = 'data.csv'; filepath = [folder filesep file]; disp(filepath);
Attempts:
2 left
💡 Hint
filesep returns the system-specific file separator character.
✗ Incorrect
filesep returns '\' on Windows and '/' on Unix. On Windows, the output is 'myfolder\data.csv'.
🧠 Conceptual
expert2:00remaining
How many parts does fileparts return for a UNC path?
In MATLAB, when using fileparts on a UNC path like \\server\share\folder\file.txt, how many output parts does fileparts return?
Attempts:
2 left
💡 Hint
fileparts always returns three outputs regardless of path type.
✗ Incorrect
fileparts returns three outputs: folder path, file name without extension, and extension. UNC paths are treated like normal paths.