demo

Quick Drop

How to copy files to a specifc folder quickly?

Shell Script

The following shell script is designed to let the users copy any file from anywhere to a destination folder quickly.

#!/bin/sh

# Check if destination folder is provided
if [ $# -ne 2 ]; then
    echo "Usage: $0 <source_file> <destination_folder>"
    exit 1
fi

source_file="$1"
destination_folder="$2"

# Check if source file exists
if [ ! -f "$source_file" ]; then
    echo "Source file does not exist."
    exit 1
fi

# Check if destination folder exists, if not create it
if [ ! -d "$destination_folder" ]; then
    echo "Destination folder does not exist. Creating..."
    mkdir -p "$destination_folder"
fi

# Extract file name from source file path
file_name=$(basename "$source_file")

# Check if the file exists in the destination folder
if [ -e "$destination_folder/$file_name" ]; then
    # File already exists, find a suitable index
    index=1
    while [ -e "$destination_folder/${file_name%.*}_${index}.${file_name##*.}" ]; do
        ((index++))
    done

    # Copy the file with the incremental index as suffix
    cp "$source_file" "$destination_folder/${file_name%.*}_${index}.${file_name##*.}"
    echo "Copied $file_name to $destination_folder with index $index"
else
    # File does not exist, simply copy
    cp "$source_file" "$destination_folder/$file_name"
    echo "Copied $file_name to $destination_folder"
fi

Integration with QuickDrop

When integrated with QuickDrop, the above script enables users to drang and drop any file from anywhere to a specific folder quickly.

We can save the above script into a copy_file.sh. We can then integarte the copy_file.sh file like the following screenshot

settings

A new Copy File quick action tile will be added to the Quick Action Panel and users can now drop any file to the tile to copy the file to the Destination folder.

drop files into predefine folders

Home - Blogs - Change logs

© An Tran - 2024. All rights reserved.