Folder Move 1.0

Automate & customize moving of files and directories [Shell]

  1. Paras Lehana
    Description
    This is a simple shell script to automate moving of directories and files to a single folder. You can associate the task to any profile and schedule it, for example, at night or on event , if target directory is modified. ​

    In my case, all the wallpapers downloaded in different directories could be moved to a single one with a single click. The directory is then configured in Tapet to import wallpapers from this directory. Similarly, I have also configured a similar script to move all my different backups for different apps in a single folder and then this folder is then synced to Google Drive. ​


    Code

    cd /sdcard/Pictures/

    folders=("Amoled Pro" "Walli Artworks" "../Papers" "Minimal O");

    IFS="";

    for folder in "${folders[@]}"; do

    file_count=$(ls $folder -1 | wc -l);

    if [ $file_count \> 0 ];

    then mv $folder/* Wallpapers/.;
    fi;
    done

    Usage
    1. Change cd <starting_directory> to any directory relative to which you would be giving the folder paths. It can be the one with most source directories.
    2. Input your source folder names in folder=("<your folder1 name" "<folder2 name>"). Give each folder name enclosed in double quotes separated by space. Here, you can also provide relative paths. For example, 'Papers' folder in my case is in the directory /sdcard/ so I used .. (one directory up) just like you'd do in terminal.
    3. I've set a single condition to move only if there's any content in the source folders. You can change the condition here to something like - only check for JPEG files or updated date.
    4. Describe type of files you want to move. I have used * to move every file.
    5. Describe your target folder in mv $folder/* <target_folder>/