Extracing only some files or images

Sometimes you are upgrading a site, but plan to just create a new site and move parts of the images and/or files. Here we will cover both the database and file-part.

Export from the database

First the easy part, the database. Create a new query. This one includes all the files, and you can sort it out in Excel afterwards:

select *, (select categoryname from category where category.categoryid = uploadedfile.categoryid) as categoryname from uploadedfile

You can offcourse also do some filtering in the query, like only include pictures that are in use in certains items. An example that takes all images that are used as thumbnail/image for items in two specific templates:

select *, (select categoryname from category where category.categoryid = uploadedfile.categoryid) as categoryname from uploadedfile where fileurl IN ( select thumbnail from item where templateid IN (85,96))

Save the report, and export the result as an Excel-file. Open the file, remove the rows you don't want to import, like all ID-rows. You might want to remove deleted files (unless you want to keep them).

If you want to import categories, you need separate Excel files for images and files.

If the new site has another name than the old one, remember to replace the 

 

Import the Excel file

To import the Excel-file into the new site, go to the tables-page in the developement tools: /er/developer/databasetables/

Select "Import" and find the UploadedFiles-table, and select that you want to import categories. You can then select what kind of files you import.

Select your Excel-file, and import.

 

Copy the selected files

Create a txt-file with all the filenames you want to copy(the files from the Excel file), in the example we call it filenames.txt. One file per line.

Create a batch-file, named something like copyfiles.bat

Add this content, and adjust the foldernames. If you include part of the folder structure in the txt-file, remember to remove that part from the script.

copyfiles.bat

for /f "tokens=*" %%i in (filenames.txt) DO ( 
    xcopy "c:\installationfolder\www\site\sitename.com\images\%%i" "x:\targetfolder" 
)

Now you have your files, and can move them into the new site.