1
votes

I'm trying to create a new node for every file thats in a specific folder using Drupal 7.

A good example of what I'm trying to create is Youtube.

When I paste a video with the .mp4 extension in a specific folder, I want Drupal to scan that folder (I will tell Drupal when to scan, so this doesn't have to happen automatically), and create a node with that video in it. I will manually set the title, description, etc... myself using the admin interface, and publish it.

I know my way around in Drupal, and its modules, but I'm not an expert. I've been googling for awhile now and the only thing I could find was:

 file_scan_directory($dir, $mask, $options = array(), $depth = 0)

I'm not asking for a complete copy/paste solution, I was just hoping someone could give me some tips, useful links or tutorials on how to do this.

1

1 Answers

1
votes

To create a node for each video file you find in a directory, you can use code similar to the following one.

  foreach (file_scan_directory($dir, '*.mp4', array('recurse' => FALSE) as $uri => $info) {
    $body_text = 'Build the body text.';

    $node = new stdClass();
    $node->type = $node_type;
    node_object_prepare($node);

    $node->title = 'Node Created Programmatically on ' . date('c');
    $node->language = LANGUAGE_NONE;

    $node->body[$node->language][0]['value'] = $body_text;
    $node->body[$node->language][0]['summary'] = text_summary($body_text);
    $node->body[$node->language][0]['format'] = 'full_html';

    node_save($node);
  }