A simple bit of code to list all files in a directory tree. I didn't write it but I will be using it soon for a site migration.
This is not WordPress specific, though I plan to use it during a site migration. I encouraged a client to avail of a Black Friday offer to purchase hosting with Siteground (affiliate link). Siteground Support copied the files over and I tested the site but, as they are running daily sales during December it was not a good time to complete the move. Instead we will do it in January.
Find the new files
Copying the database over will be easy – I’ve already tested this. No data needs to be changed because the url is not changing.
The difficult part is copying over files (primarily the Media Library) that might have been added since Siteground Support copied the files. Below is a script that lists all files in the ‘uploads‘ directory. If I run it on both sites and do a diff I will see the list of new files.
Code from StackExchange
I decided to use the answer with the RecursiveIteratorIterator/RecursiveDirectoryIterator code. The only thing I don’t like about the code is that it will traverse down the directory tree as it finds subdirectories so you may not see the contents of any individual directory grouped together in the list. Maybe the usual scandir() method can be modified to record all files in a directory before going down the subdirectories – that will be a task for me. Another task is to list file timestamps and sizes (and maybe even checksums).
There are better solutions
I realise that there are better solutions for migrating a web site e.g. Migrate DB Pro, this is a simple way to list new files, and some code that I may use every now and again.