Moodle 2.0 - how to create folder/directory

Moodle 2.0 - how to create folder/directory

by Marta Muñoz -
Number of replies: 5

Hi!!

I'm developing a module, i create my files without any problem, but i'd like create folders into my private area. My code in order to create files are:

               $fs = get_file_storage();
               $contextuser = context_user::instance($USER->id);

               // Prepare file record object
               $fileinfo = array(
                   'contextid' => $contextuser->id, // ID of context
                   'component' => 'user',     // usually = table name
                   'filearea' => 'private',     // usually = table name
                   'itemid' => 0,               // usually = ID of row in table
                   'filepath' => '/',           // any path beginning and ending in /
                   'filename' => $filename); // any filename
               
               $fs->create_file_from_string($fileinfo, $content); 


I have read that if you want a directory 'filename' must be '.' . 


Thanks in advance smile

Average of ratings: -
In reply to Marta Muñoz

Re: Moodle 2.0 - how to create folder/directory

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Just set the filepath property to the desired directory (do not forget the leading and trailing slashes, as the inline comment says). Moodle will create the required subfolders for you. Not sure if creating an empty directory is supported, but I guess so. You can simply try it by creating an empty file called '.' in the given path.

In reply to Marta Muñoz

Re: Moodle 2.0 - how to create module in moodle

by Balvant Ramani -

I am beginner at moodle. I want to create module in moodle. Where to start ? How moodle works for developer ? Please help me.

In reply to Balvant Ramani

Re: Moodle 2.0 - how to create module in moodle

by Davo Smith -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Balvant,

I can't quite see the connection between your post and the discussion you have added it to; if you want to ask a brand new question, it is much better to start a new discussion, rather than posting on an unrelated discussion.

With that said - take a look at http://docs.moodle.org/dev as a starting point.

In reply to Marta Muñoz

Re: Moodle 2.9 - how to create folder/directory

by Nilesh Pathade -

I am beginner in moodle development , I want to create folder on simple button click . please help me