move downloaded files to particular directories - inotify for dummies?

Viewed 37

I wonder whether nobody else wants to move files downloaded from the web to file-specific directories? - Bank account statements go to various "Bank account statements" folders, depending which account it is, invoices go to their specific folders etc.

Assumed they all have their characteristic file name beginning, it should not be so difficult to get that automatized. There is a firefox plugin for that, but I could never make it work. So my idea was to use inotify for the download folder (or another suitable tool). But I never found really dummy-proof instuctions how to obtain that.

Would someone be so kind and provide all the steps to set up such a service?

Thanks a lot in advance, Wolf

1 Answers

After quite some trial and error, I came to a working solution. This script sorts downloaded files with certain patterns to the defined target directories:

#!/bin/bash

cd <my-download-directory>
inotifywait -mq -e moved_to --format %f <my-download-directory> | while read FILE
echo "name of new file: "$FILE
do
if [[ $FILE =~ regex-search-pattern1 ]]; then mv $FILE <target-directory1> ; fi
if [[ $FILE =~ regex-search-pattern2 ]]; then mv $FILE <target-directory2> ; fi
if [[ $FILE =~ regex-search-pattern3 ]]; then mv $FILE <target-directory3>; fi
... more if desired
done

In general such a feature is quite useful - I'd really like to have a GUI for it.

Cheers, Wolf

Related