/* Written by Rainer M. Engel, 2013 | Use at your own risk! What it does: Folder_Synchronize asks for two inputs; a source and a target folder. Then the macro will copy all necessary files from source to target to build a mirror (synchronize both folders). To achieve this only new or updated files will be copied to target and older and therefore "orphan" files will be deleted from traget folder. The source folder and its contents are not modified! */ requires("1.47j"); print("\\Clear"); print("Folder Synchronize .. (building mirror)"); print("_____________________________________________"); dir1 = getDirectory("Select source folder .."); dir2 = getDirectory("Select target folder (mirror of source) .."); dir1 = replace(dir1, "\\", "/"); dir2 = replace(dir2, "\\", "/"); print("Source-Dir.: "+dir1); print("Target-Dir.: "+dir2); if (lengthOf(dir1) <= 2 || lengthOf(dir2) <= 2) { exit("This macro stops here, since one or more inputs might be not usable!"); } wfu = getBoolean("Please check source and target folder in log-window.\nDo you want to continue?"); if (wfu == false) { exit(); } print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"); starttime = getTime(); // TIMING START POINT //Fill VisualLogStatus-Array............................................................. bars1= "#####################################"; bars2= "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"; StatBarA = newArray(); for (i=0; i<(lengthOf(bars2)+1); i++) { bars1mod = substring(bars1, 0, i); bars2mod = substring(bars2, i, lengthOf(bars2)); StatBarA = Array.concat(StatBarA,bars1mod+bars2mod); } //....................................................................................... //count = 0; //countFiles(dir1); //print("files found : "+count); // Get SOURCE folder contents............................................................ //§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ List.clear() //Resets the list print("Analyzing SOURCE-FOLDER .."); n = 0; f = 1; processFiles(dir1); print("\\Update:Source-Folder: "+List.size+" files found, calculating size .."); fileList = List.getList; sFiles=split(fileList,"\n"); //Show FileSize sSize = 0; for (i=0; i delete them ........... ///////////////////////////////////////////////////////////////////////////////////////// print(" - searching abandoned/orphan files in target folder .."); //Get all folders of target files tFolderA= newArray(); for (i=0; i "+tDeletionListA.length+" folders and their contents will be deleted!"); delCount = 0; for (i=0; i delete them.................................. ///////////////////////////////////////////////////////////////////////////////////////// List.clear() //Resets the list n = 0; f = 1; processFiles(dir2); fileList = List.getList; tFiles=split(fileList,"\n"); //Compare this list with source -> delete orphan files in target for (i=0; i "+tDeletionListA.length+" folders ("+delCount+" files) have been deleted!"); print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"); //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // Copy new and newer files from Source to Target ....................................... //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ print("Copy new & newer files (Source -> Target) .."); //Get all folders in Source and if neccessary create them in target sFolderA= newArray(); for (i=0; i parseInt(tFileD)) { nada = File.copy(sFile, tFile); filesC++; //print("file to copy: "+sFile); //print("sFileD: "+sFileD+" | tFileD: "+tFileD); } } else { nada = File.copy(sFile, tFile); filesC++; //print("file to copy: "+sFile); //print("sFileD: "+sFileD+" | tFileD: "+tFileD); } //Visual Status-Bar ............................................... n = StatBarA.length; p1 = (100/sFiles.length)*i; //length to refer to in % p2 = p1*(n/100); p2r = round(p2); p = d2s(p1, 2); if (p2r < StatBarA.length) { print("\\Update:"+"["+StatBarA[p2r]+"] "+p+"% | "+(i+1)); } else { print("\\Update:"+"["+StatBarA[n-1]+"] "+p+"% | "+(i+1)); } //................................................................. } print("\\Update:"+"["+StatBarA[n-1]+"] 100.00%"); //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ endtime = getTime(); // TIMING END POINT print("_____________________________________________"); print("Folder Synchronize, "+sFiles.length+" files were mirrored/syncronized"); print(" -> only "+filesC+" files had to be copied this time"); print("Processing Time (HH:MM:SS): "+msToTimeCode ((endtime - starttime))+" | ms: "+(endtime - starttime)); print("_____________________________________________"); // F-U-N-C-T-I-O-N-S--------------------------------------------------------------------- function byteSize(bytes) { if (bytes < 1048565514) { sizeB = d2s(bytes/pow(1024, 2), 2)+" MB"; } else if (bytes > 1073741824000) { sizeB = d2s(bytes/pow(1024, 4), 2)+" TB"; } else { sizeB = d2s(bytes/pow(1024, 3), 2)+" GB"; } return sizeB; } function ArrayUnique(array) { array = Array.sort(array); array = Array.concat(array, 999999); uniqueA = newArray(); i = 0; while (i<(array.length)-1) { if (array[i] == array[(i)+1]) { //print("found: "+array[i]); } else { uniqueA = Array.concat(uniqueA, array[i]); } i++; } return uniqueA; } function countFiles(dir) { list = getFileList(dir); for (i=0; i