Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Is it possible to create .md files in batch?

Started by Jayesh Gohel 8 years ago · 5 replies · 782 views
8 years ago

Hello,

Idea is to create a photo-gallery from images organised into folders (a lot of them). I do not want to create a .md file using the admin panel - as I would have to go through each link and save the page. Is it possible to create pages automatically or just add a simple .md file in batch mode?

8 years ago

Hello,
This is currently not possible with grav or admin plugin.
You could however create a script to create a md file in every folder.

👍 1
8 years ago

Thank you for your answer @paul. I was looking at a Grav (or Grav+Admin) based solution here. You think it is possible to write a plugin that crawls through the folder structure and performs actions based on some rules?

8 years ago

yep that should be doable :-) @gnat

8 years ago

@RobLui @paul Would really appreciate any pointers showing how this can be achieved.

8 years ago

Haven't done it myself yet, but should be something in the line of : http://php.net/manual/en/class.recursivedirectoryiterator.php

PHP
  <?php

  $Directory = new RecursiveDirectoryIterator('path/to/project/');
  $Iterator = new RecursiveIteratorIterator($Directory);
  $Regex = new RegexIterator($Iterator, /^.+\.extention$/i', RecursiveRegexIterator::GET_MATCH);

  ?>

or / and a combination of:
https://stackoverflow.com/questions/24783862/list-all-the-files-and-folders-in-a-directory-with-php-recursive-function

PHP
function getDirContents($dir){
    $results = array();
    $files = scandir($dir);

        foreach($files as $key => $value){
            if(!is_dir($dir. DIRECTORY_SEPARATOR .$value)){
                $results[] = $value;
            } else if(is_dir($dir. DIRECTORY_SEPARATOR .$value)) {
                $results[] = $value;
                getDirContents($dir. DIRECTORY_SEPARATOR .$value);
            }
        }
}

print_r(getDirContents('../../folder'));

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 8 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago