Update File Path in Drupal

We have a site that we had been migrating since Drupal 4. Few days back when we tried to migrate the same from Drupal 6 to Drupal 7. There was an issue with respect to file location that was present since previous upgrades. To resolve that a symlink was created called "files" with linked to sites/default/files during D6 upgrade. This led to first loss of many files as Drupal does not handle symlink based file saving well. Secondly the files created were saved under public://files/filename.ext instead of public:://filename.ext which caused created files not being accessible.

To resolve the file path we tried to research (via google) various alternatives. There were suggestions on using file api to modify the path which we tried and which didnt . Finally we resolved to simple MySQL based search and replace:

UPDATE `files` SET `filepath` = REPLACE(`filepath`, "sites/default/sites/default/files/", "sites/default/files/");

This updated the files but some had path like: "sites/default/sites/default/files/" which needed to be fixed.

UPDATE `files` SET `filepath` = REPLACE(`filepath`, "sites/default/sites/default/files/", "sites/default/files/");

This fixed the issue. Secondly the public directory was changed to sites/default/files instead of symlink "files" to prevent further complication.

Hope it helps.