Software for sorting files into folders

Hi!

My friend has been dangerously uncareful with their external hard drive usage and now possesses a drive with probably thousands of files in a single folder.

They have asked my help in sorting the bloody thing (being even less adept at computers than I am). I was wondering if there was software that could sort files into folders based on given characteristics? Even a program capable of performing this based on just one or two parts of the file name would be immensely helpful. A lot of the discussion I have searched thus far have consisted of writing a Python code or script of sorts and I would prefer to explore even a limited program before trying to venture into the unknown.

Thanks for reading my message!

Any file manager could already do that, you would have to create the folders yourself though.

Sort by file type, by size, you will already be able to kinda sort manually and then you could select by chunks and move to folder (like images, music, videos, PDF or whatever the type is), size could help to sort within folders then too (movies, short clips), and the integrated search of the file manager within the folder could help to find by portion of the file name.

It does what you would like, except the automatic creation of folders but that would require a program to understand your goals.

3 Likes

The downside with using a graphical file manager is most of them can get slow when managing a lot of files in a single folder – moreover in the thousands.
Also, some file managers have more detailed search features than others. From a quick search, something like krusader may suit you.

1 Like

Perhaps try Organizer available as a Flatpak or in the AUR (Arch User Repository) as organizer-git.

1 Like

if different formats (~/Documents/ ?), you can use a script for class by mime type :question: (is a first step)

#!/usr/bin/env bash
echo "source directory: $1"
[ -z "$1" ] && { echo "no bazard directory"; exit 127; }

cd "$1"
for filename in *.*; do
    dest=$(file -b "$filename" --mime-type)
    if [ -n "$dest" ]; then
        echo "mkdir -pv \"$dest\""
        echo "mv \"${filename}\" \"${dest}/${dest}\""
    fi
done
#TODO: remove echo mkdir and mv ;)

After use gui (catefish, …)

3 Likes

Thanks for all the suggestions!

This has given me a lot of options to proceed with.

I have a script that moves the correct server log file into a directory identical to the server name.

It looks for a dash (-) in any file name and then creates a bunch of directories and then moves all the files containing the server name into the server directory.

Disadvantage: Every file has to have a - in it, but you could use a space too I guess.

#!/bin/bash
echo About to make changes in this directory:
readlink -f .
read -n1 -s -r -p $'Press space to check file errors here...\n' szInput
echo Dual spaces files:
ls *\ \ *
read -n1 -s -r -p $'Press space to simulate directory creation here...\n' szInput

if [ "$szInput" = '' ]; then
  # szInput is empty at IFS whitespace: space, tab, LF or enter
  echo The following directories will be created:
  find . -maxdepth 1 -type f | cut --delimiter='-' --fields=1 | sort --unique |
  while read server ; do
    echo $(sed 's/ /\\ /g' <<< "$server")
  done

  read -n1 -s -r -p $'Press space to create directories...\n' szInput
  if [ "$szInput" = '' ]; then
    find . -maxdepth 1 -type f | cut --delimiter='-' --fields=1 | sort --unique |
    while read server ; do
      echo $(sed 's/ /\\ /g' <<< "$server") >> /tmp/MakeDirs.sh
      #mkdir $(sed 's/ /\\ /g' <<< "$server")
    done
    # Set no-globbing to create script to chain to
    set -o noglob
    echo Moving files
    # overwrite existing chain file
    echo "#!/bin/bash" > /tmp/move-files.sh

    clear
    echo Generating files...
    # Find everything except hidden directories (! path .)
    find . -maxdepth 1 ! -path . -type d |
    while read server ; do
      # echo to console and to file
      echo mv $(sed 's/ /\\ /g' <<< "$server")\\\ -?* $(sed 's/ /\\ /g' <<< "$server")
      echo mv $(sed 's/ /\\ /g' <<< "$server")\\\ -?* $(sed 's/ /\\ /g' <<< "$server") >> /tmp/move-files.sh
    done

    chmod a+x /tmp/move-files.sh
    read -n1 -s -r -p $'Press [Ctrl][C] to exit before moving files...\n' szInput
    /tmp/move-files.sh
  else
    echo -e $FRED Directories NOT created
  fi
else
  echo $FYEL Exited by user; wrong directory???
fi

:+1:

2 Likes