Created
April 10, 2009 13:16
-
-
Save lukeredpath/93079 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Example: monitor a folder for new torrents and move them elsewhere | |
(e.g. I move them to a network drive that is monitored by | |
Transmission on my media centre. | |
--> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>lukeredpath.TorrentMonitor</string> | |
<key>OnDemand</key> | |
<true/> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/luke/.bin/organise-files</string> | |
<string>-glob</string> | |
<string>*.torrent</string> | |
<string>-src</string> | |
<string>/Users/luke/Downloads/</string> | |
<string>-dest</string> | |
<string>/Volumes/Media/Downloads/Torrents</string> | |
</array> | |
<key>WatchPaths</key> | |
<array> | |
<string>/Users/luke/Downloads</string> | |
</array> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## REQUIRES optiflag gem | |
## Usage: | |
## -verbose (Optional, takes 0 arguments) | |
## -glob (Required, takes 1 argument) | |
## Glob pattern to match against src contents | |
## -h (Optional, takes 0 arguments) | |
## Help | |
## -src (Required, takes 1 argument) | |
## The source folder to organise | |
## -dest (Required, takes 1 argument) | |
## The directory to move the matched files into | |
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'optiflag' | |
require 'fileutils' | |
module OrganiseFiles extend OptiFlagSet | |
flag "glob" do | |
description "Glob pattern to match against src contents" | |
end | |
flag "src" do | |
description "The source folder to organise" | |
end | |
flag "dest" do | |
description "The directory to move the matched files into" | |
end | |
optional_switch_flag "verbose" | |
def self.move_files_of_type!(glob, src, dest, verbose=false) | |
Dir[File.join(src, glob)].each do |file| | |
FileUtils.mv(file, File.join(dest, File.basename(file))) | |
puts "Moved #{file} to #{dest}" if verbose | |
end | |
end | |
and_process! | |
end | |
$VERBOSE_MODE = ARGV.flags.verbose? | |
OrganiseFiles.move_files_of_type!( | |
ARGV.flags.glob, ARGV.flags.src, ARGV.flags.dest, $VERBOSE_MODE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment