How to cd a file with date in its name

Viewed 100

I'm trying to be able to create several sub-folders within a folder on the main path I have already created, but I get a message saying the folder I'm trying to "cd" isn't valid. I would appreciate if someone could explain why this is happening, and either help me fix my cd code or give me an alternative way to access this folder.

This is for MATLAB 2019. I'm trying to get the code to auto-generate a folder with the date and time (which you can see in the first line below), and then create a sub-folder "Participant 1" (i.e. when you double click on the date and time, you open the sub-folder "Participant 1"). I then want to add a further sub-folder, "EMG_Data". I'm getting stuck at the point where I have to cd for the folder that has the currDate and "Participant 1" in it. As stated above, I would like to be able to create an additional sub-folder called "EMG_Data" within the "Participant 1" sub-folder, but I don't know how to get to the "Participant 1" folder (presumably I would have to cd it) because I don't know how I'm supposed to format the date (currDate) within the cd or other functions.

currDate = strrep(datestr(datetime), ':', '_');
mkdir('SMC Project Data Collection')
cd('C:/Users/wynkoopp/Documents/MATLAB/SMC Project/SMC Project Data Collection/')
mkdir(currDate,'Participant 1')
cd('C:/Users/wynkoopp/Documents/MATLAB/SMC Project/SMC Project Data Collection/currDate/Participant 1/')
mkdir('EMG_Data')

% Want the 'currDate' above to always be integrated into cd function above
% at the end, since name of folder will vary

I expect to have the subfolder 'EMG_Data' formed in the subfolder 'Participant 1', but this is not happening. Instead, I get:

Error using cd

Cannot CD to C:\Users\wynkoopp\Documents\MATLAB\SMC Project\SMC Project Data

Collection\currDate\Participant 1 (Name is nonexistent or not a directory).


Error in Paulcopydirectorygenerator (line 5)

cd('C:/Users/wynkoopp/Documents/MATLAB/SMC Project/SMC Project Data

Collection/currDate/Participant 1/')

1 Answers

The line mkdir(currDate,'Participant 1') create a folder in the folder with the current date. Your cd command tries to access to another folder which does not contain the current date.

Related