How to automatically create nodes from a bulk file upload
Using Bulk File Nodes you can create unlimited number of nodes at once .


  Bulk File Nodes allows a user to upload or import many files at once, and have many individual nodes created, one for each file . Where this module significantly differentiates from other modules like Bulk Media Upload is that after uploading/importing the file(s), the user is given the opportunity to edit all of the fields for each node in a single form.


This module creates a node for each file and you can edit the fields of each node after uploading.





Solution 1

You are right, Bulk File Nodes works only with images. since you need to create nodes programmatically and assign the files to the nodes you can use the following code to create a node without a file field

$uid = SOME_USER_UID
$values = array(
        'type' =&gt; 'THE_CONTENT_TYPE',
        'uid' =&gt; $uid,
        'status' =&gt; 0,
        'comment' =&gt; 0,
        'promote' =&gt; 0,
        'language'  =&gt; 'en'
);
$entity = entity_create ('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity); 
$ewrapper-&gt;title-&gt;set('THE_TITLE');

$ewrapper-&gt;save();


But from Attaching image files to nodes programmatically in Drupal 7
 you can use the following code to attach the file to the above node

$filepath = drupal_realpath('misc/druplicon.png');
 // Create managed File object and associate with Image field.
 $file = (object) array(
'uid' =&gt; 1,
'uri' =&gt; $filepath,
'filemime' =&gt; file_get_mimetype($filepath),
'status' =&gt; 1,
  );

// We save the file to the root of the files directory.
$file = file_copy($file, 'public://');

$ewrapper -&gt;field_file[LANGUAGE_NONE][0] = (array)$file;


This code should be above $ewrapper-&gt;save(); line.

Solution 2

You can also create the nodes without file fields as described above. and for each node with $node variable Programmatically Attach Files to Node. 

// We have complete file path.
$file_path = '/whatever/path/to/file/sample.pdf';

$file = new stdClass;
$file-&gt;uid = $node-&gt;uid;
$file-&gt;filename = pathinfo($file_path, PATHINFO_BASENAME);
$file-&gt;uri = $file_path;
$file-&gt;filemime = file_get_mimetype($file_path);
// Make it permanent, otherwise it will get deleted later.
$file-&gt;status = FILE_STATUS_PERMANENT;

// Save file object to make it a 'managed file'.
file_save($file);

// We will save file under this location.
$destination = 'public://PDFs/';

// Make sure destination directory exists before moving files to that path.
// This will create directory if it does not exists.
file_prepare_directory($destination, FILE_CREATE_DIRECTORY);

// Now attach file to the file field.
$node-&gt;field_pdf[$node-&gt;language][0] = (array) $file;

// Default file type field comes with this extra properties.
$node-&gt;field_pdf[$node-&gt;language][0]['display'] = 1;
$node-&gt;field_pdf[$node-&gt;language][0]['description'] = 'Our special PDF';

// Save node to make the attachment effective.
node_save($node);