You are not logged in.

#1 2012-05-05 08:12:11

JackH79
Member
From: Australia
Registered: 2009-06-18
Posts: 663
Website

[SOLVED] Auto-sort files in folders

Came across the "Magic Folder" plasmoid on a friend's KDE setup and liked the idea very much, especially for my downloads folder (I tend to download many things and then go through them later to sort away).

I found the "Download Sort" plugin for Firefox, but it doesn't always work and doesn't seem to be maintained anymore (last release 2006).
I also found this shell script on the Ubuntu forums, but it doesn't do what I want.

Does anyone know of a way (or a ready made program) that could do the following:
- Check every file that is placed in folder "X" (eg ~/downloads) [not only by Firefox, but always] and automatically distribute them to another folder by mime type or file extension
- This is not a must, but a nice and useful feature: automatically create subfolders by date for certain file types (useful for PDFs etc., but not needed for videos or music)

Thanks in advance

Last edited by JackH79 (2012-05-06 14:15:14)

Offline

#2 2012-05-05 11:42:32

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: [SOLVED] Auto-sort files in folders

I don't know about a ready program, but you can write a simple bash script to do that.
(I think this is very simalar to your ubuntu link, I can't view it).

#!/bin/bash

while read filename; do
 echo -n "$filename "
 case $(file -b --mime-type "$filename") in
  image/png) 
   echo "is a png image"
   mv -n "$filename" /somewhere/png/
   ;;
  image/*) 
   echo "is an image"
   mv -n "$filename" /somewhere/otherimages/
   ;;
  application/pdf)
   echo "is a pdf"
   destdir="/somewhere/pdf/$(date +%Y.%m.%d)"
   if [[ -d "$destdir" ]] || mkdir -p "$destdir"; then
    mv -n "$filename" "$destdir/"
   fi
   ;;
  *)
   echo "has mime $(file -b --mime-type "$filename"). I don't know what to do"
 esac

done < <( find /path/to/magic/folder -type f )

Offline

#3 2012-05-05 16:19:58

briest
Member
From: Katowice, PL
Registered: 2006-05-04
Posts: 468

Re: [SOLVED] Auto-sort files in folders

..and pair it with incron to make it magical without KDE wink

Offline

#4 2012-05-05 21:54:44

parintachin
Member
Registered: 2009-05-25
Posts: 72

Re: [SOLVED] Auto-sort files in folders

fsniper in aur does what you need

Offline

#5 2012-05-06 14:14:38

JackH79
Member
From: Australia
Registered: 2009-06-18
Posts: 663
Website

Re: [SOLVED] Auto-sort files in folders

Thanks very much for all your suggestions.

Fsniper does exactly what I was looking for
So a special 'thank you' and a smiley face for parintachin: smile

Cheers

EDIT: Just for reference, I put up a wiki entry with some additional infos, including a way to run it as an rc.d daemon

Last edited by JackH79 (2012-05-28 08:57:48)

Offline

Board footer

Powered by FluxBB