0

I have a folder named "fp" wherein lies folders for each subject. Within each subjects folder lies further set of folders for subjects data named 000001, 000002 etc.

I can store the directory for the "fp" folder in a variable. And then I would like to create another variable with another directory for each subject.
It is as if I want to create a variable subjects = "sub*" that means that all subjects folders begin with "sub"....

And then further on, define another directory in the same way for the data folder = subjects/'0000000*' meaning that all data folders within each participants folder begin with 7 zeros (or whatever). How can this be done?

I do not want to check if they exist or create if necessary. I want to go through each subject and each subjects datafolders to finally obtain information from the first file in the datafolder

in MATLAB this could be done like follows, I think:

   subjectPattern = 'sub*';  % name pattern
   rootDir = '...../fp'; 
   dirs = dir(fullfile(rootDir, subjectPattern));
augusti
  • 401
  • 3
  • 6
  • 16
  • Possible duplicate of [How to check if a directory exists and create it if necessary?](http://stackoverflow.com/questions/273192/how-to-check-if-a-directory-exists-and-create-it-if-necessary) – FLab Mar 10 '17 at 10:49
  • I do not want to check if they exist or create if necessary. I want to go through each subject and each subjects datafolders to finally obtain information from the first file in the datafolder – augusti Mar 10 '17 at 10:52
  • 1
    It's not clear what problem you are having trying to achieve your goal. – Peter Wood Mar 10 '17 at 10:53
  • It seems to me like you want to `os.listdir` in the folder and then create a dict entry for each folder. As i'm not sure, I suggest you post a treeview of the folder structure and a data structure you'd like to receive. – nir0s Mar 10 '17 at 10:57

0 Answers0