Moving all images to an external drive

I have a better script now. Works with sub-folders and more elegant.
I think its straightforward, commented. Test with one case with few sub-folders, works fine.

/* NOTE: Variables 
   	variable string expected between '' like: 'sting' Example: 'moonshine_folder' and NOT moonshine_folder 
    variables: var_src_folder_name -> the source folder name ; var_dst_folder_name -> the destination folder name. Note: just a folder name, and not full path!
*/ 

/* Script Part 1 - Update the 'main' folder - Script Part 1 start */
UPDATE Sources 
 set FolderId  = (select fo_dst.Id from folders fo_dst where fo_dst.name = :var_dst_folder_name) /* destination folder - only folder name - please be some unique */ 
where 1 = 1
  and FolderId = (select fo_src.Id from folders fo_src where fo_src.name = :var_src_folder_name) /* source folder - only folder name - please be some unique */
  and (SELECT count(*) from folders fo_check_dst where fo_check_dst.Name  = :var_dst_folder_name) = 1  /* dst folder unique - if not, than not execute*/ 
  and (SELECT count(*) from folders fo_check_src where fo_check_src.Name  = :var_src_folder_name) = 1  /* src folder unique - if not, than not execute*/
/* Script Part 1 - Update the 'main' folder - Script Script Part 1 end */  
  
/* Script Part 2 - Update the 'subfolder(s)' folder - Script Part 2 start */  
Update Folders 
 set ParentFolderId = (select fo_dst.Id from folders fo_dst where fo_dst.name = :var_dst_folder_name) 
where 1 = 1
  and ParentFolderId = (select fo_src.Id from folders fo_src where fo_src.name = :var_src_folder_name)
  and (SELECT count(*) from folders fo_check_dst where fo_check_dst.Name  = :var_dst_folder_name) = 1  /* dst folder unique - if not, than not execute*/ 
  and (SELECT count(*) from folders fo_check_src where fo_check_src.Name  = :var_src_folder_name) = 1  /* src folder unique - if not, than not execute*/
/* Script Part 2 - Update the 'subfolder(s)' folder - Script Part 2 end */

/* Description  
  
     v.01.01.00 - 2025.12.22 - andras - add: check for src and dst folder unique, subfolder handling, variable usage for no typing in code. Not check for: folder exist in dst (expect Dst is empty)
     v.01.00.00 - 2025.12.22 - andras - works but no checking, no subfolder handling, nothing just plain single folder handling. Note: dount use if sub-folder inside source folder! 
     
     Its tested under Windows version database. Its not work under Mac version (i guess under Mac is some similar at general, but with some 'Z' fields, etc. I can't test it under Mac, if someone interested, i try to help)
     Use in your own risk. May good idea to backup the database  
     PL version: 9.3.2 However i think works all 9.x (Win)
     
     General overview: 
     If you like to move (manually, outside from PL) a folder (and all subfoders in it) to diffent folder (even its in different drive) than this can update the PL db for changes.
     This script(s) update PL db in the 'folder' (folder name) data table and related 'sources' (the photo files) data table. 
     As its 'just' changes this, all other thing works as expected: history, projects, allready generated thumbnail and preview files stay is sync, etc.
     Example in few step: 
     	Source folder: d:\Photos\PL9_Test\db_move_test_src\  
     	Destination folder: e:\temp\db_move_test_dst\
     	Execute script with folder parameters ('db_move_test_src', 'db_move_test_dst') -> its update the PL db
     	Move the source folder(s) content manually (all photos + .dop + all sub-folders) 
     	Your done 
     
     Few thing expected (in current script version): 
       - The destination folder NOT contains folder names what exist in Source folder! No check in the script. 
       - Both source and destination folder need to be known by PL. So, at least onece you need to click to the folders in PL (even the destination may empty)
       - Both source and destination folder need to be unique in PL. Example: PL can't know like c:\photos\test01 and d:\photos\test01 as 'test01' folder name is not unique.
     
     Note:  
       - Not tested for Projects and stuffs like that - however as i think, everything just needs to works fine.
       - Not tested for root folders (example: d:\photostuffs ), however i guess its just works fine.
    
      Changes:
       - 01.01.00 Updated - Dst sub-folder update added - 01.00.00 part: Use only if NO sub-folder inside of the source folder (in this script version)
       - 01.01.00 Updated - Src and Dst folder unique check added - 01.00.00 part: No check at all, like folders exist or not in PL db, or has sub-folder, etc.(in this script version)
       - 01.01.00 Updated - Src sub-folder update added - 01.00.00 part: Not recursive - like sub-folder (in this script version)
     
     How to use:
       Step 0. -> Make sure source folder(s) is indexed in PL
       Step 1. -> Make sure source folder name is unique - may good idea to rename some 'temporary unique' name (or prefix) in PL like 'moonshine_folder' (i guess 'moonshine' is may uique for you folder structure)
       Step 2. -> Make sure destination folder name is unique - may good idea for some temporary like 'moonlanding_folder' - source folder need to be known by PL!
       Step 3. -> Quit from PL
       Step 4. -> Connect to PL DB + Open/Copy SQL script
       Step 5. -> Fill the destination and source folder name in the script parameters (variable). Only the folder name (and not full path)
       	            - variable string expected between '' like: 'sting' Example: 'moonshine_folder' and NOT moonshine_folder 
                    - variables: var_src_folder_name -> the source folder name ; var_dst_folder_name -> the destination folder name. Note: just a folder name, and not full path! 
       Step 6. -> Run script Script Part 1 (select only the part 1 start/end section and run it).
       				- The if no error during the execution, then good to go.
       				- The update count is the photos amount of the folder (and not with all in the sub-folders)
       				- If update count is 0 than: folder names (source, destination) is not unique or folder names misstyped or no photo in the source folder. Please check it if 0.
       				- If error, than error, who knows why. 
       Step 7. -> Run script Script Part 2 (select only the part 2 start/end section and run it).
       				- The if no error during the execution, then good to go.
       				- The update count is the sub-folders inside of source folder. Only the 'below sub-folders'. Sub-folders below the sub-folders doesent count. 
       				- If update count is 0 than: folder names (source, destination) is not unique or folder names misstyped or no sub-folder at all. Please check it if 0.
       				- If error, than error, who knows why.  
       Step 8. -> Move manualy the files (raw + .dop) from source folder (and also all the sub-folders if has) to destination folder. 
       Step 9. -> Rename (manually) the source folder to something else (or just simple delete)
       Step 10. -> Start PL
       Step 11. -> Browse the destination folder. You see the photos fine, all history or relevant is just okay. 
       Step 12. -> Rename in PL your destination folder to final name (if you use like 'moonlanding_folder')
*/