Saturday, September 23, 2023

Finding files differences between folders

I wrote a small script to find the files which are not present between two folders. Initially I used diff which works fine for source codes but when I want to just check for folders and files newly added to a directory without having to compare its content, diff is very slow. I wrote it mainly for backup purposes. For example, I have documents written to optical disk for archiving. I want to know which are the newly added files since the archival. So I can quickly compare the folder from optical disk and the hard drive to get a list of file I need to backup.
#!/bin/bash

if [ $# -ne 2 ]; then
    echo "Usage: $0  "
    exit 1
fi

folder1_path="$1"
folder2_path="$2"

# List all files in first folder
find "$folder1_path" -type f | sed "s#${folder1_path}/##" | sort > files_in_folder1.txt

# List all files in second folder
find "$folder2_path" -type f | sed "s#${folder2_path}/##" | sort > files_in_folder2.txt

echo 'Files in folder1 that are not in folder2:'
comm -23 files_in_folder1.txt files_in_folder2.txt

echo ''
echo 'Files in folder2 that are not in folder1:'
comm -23 files_in_folder2.txt files_in_folder1.txt

# Clean up
rm files_in_folder1.txt files_in_folder2.txt
For checking content difference
#!/bin/bash

# find difference between file and folder contents

diff -rq "$1" "$2"

Thursday, September 21, 2023

Bookmarks Organiser v4.0 is live

Bookmarks Organizer is a nifty browser extension that automatically sorts bookmarks alphabetically when added. We can also sort all bookmarks manually using the reorder button. Chrome has moved to new version of manifest which is v3 making incompatible differences in how extensions work. All manifest v2 extensions will be removed from the store starting Jan 2024.

The previous version of the Bookmarks Organizer used web worker for compute intensive sort operation. With manifest v3, the default background script runs as a service worker. Currently chrome cannot create nested workers. So I rewrote the entire extension as I cannot use web worker and made it more streamlined. The current version excludes Other Bookmarks/Other Favourites from sorting so that any manual ordering can be placed there.

Get Bookmarks Organizer for Google Chrome which is a featured extension in the chrome web store.
Now Bookmarks Organizer is also available for Microsoft Edge browser as Edge Add-on!