How to reorganise files location without updating each node manually? In my file system, I have different folders where are stored the files linked to the nodes (either pictures in the body of the node or pictures in a 'Gallery' field I added to custom content type).  

I'd like to reorganize all these folders in a more structured way.
How can I do that without editing each of these nodes?  

Is there a way to update the database, e.g. change mydomainname/sites/default/files/mypicture.png (or whatever) to mydomainname/sites/default/files/pictures/yyyymmdd/mypicture.png where yyyymmdd is related to an event, for example?  

My version of Drupal is 8.5.6.
Yes there is a way to fo this, I have the same situation in my previous project and I have achieved this by using below code:

    $field_name = 'FIELD_MACHINE_NAME';
    $entity_type = 'ENTITY_TYPE'; // Node or user
    $bundle = 'BUNDLE'; // Content Type.
    $table_field = $field_name . '_target_id';
    $table = $entity_type . '__' . $field_name;
    $db_conn = \Drupal::database();
    $query = $db_conn-&gt;select($table, 'th');
    $query-&gt;leftJoin('file_managed', 'fm', 'fm.fid = th.' . $table_field);
    $query-&gt;fields('th', ['entity_id', $table_field]);
    $query-&gt;fields('fm', ['filename']);
    $query-&gt;condition('bundle', $bundle);
    $entity_results = $query-&gt;execute()-&gt;fetchAll(\PDO::FETCH_ASSOC);
    foreach ($entity_results as $result) {
      $fid = $result[$table_field];
      $file_load = File::load($fid);
      if ($file_load) {
        $new_directory = 'NEW DIRECTORY PATH';
        $new_uri = "public://" . $new_directory . "/" . $file_load-&gt;getFilename();
        $db_conn-&gt;update('file_managed')
          -&gt;fields([
            'uri' =&gt; $new_uri,
          ])
          -&gt;condition('filename', $file_load-&gt;getFilename())
          -&gt;condition('fid', $fid)
          -&gt;execute();
        drupal_set_message('File path changes successfully for for node id ' . $result['entity_id']);
      }
      else {
        drupal_set_message('Unable to load file for node id ' . $result['entity_id'], 'warning');
      }
    }


Here you have to be very careful while moving this to production. Backup DB and files before running this code.

And drush cr or clear cache after running this code for every field.