file_sorter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjZhNDVmNmExNThhNjY1OTUwZDk0ZTE2ZDllN2RkYjRjNDdlNDZhZA==
5
+ data.tar.gz: !binary |-
6
+ MjY1ZWE0N2E0YzY5YTZlMjgyMTAxNzdiYmRiMjQxN2Q4ODVmZGZlYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTI2NmM3N2M1ZWNiMTI3N2Y1MTdiY2JmMDZlMjhhZTU4ZTliNWViYTAwNmM3
10
+ YzY4ZmZkN2JhMjg2MjM1NWEyMTgyOTE0YTdkMWQ3YmNhMzIxNTU2YWI5YTQz
11
+ Mzk4N2Y2YmI3MDc1OTFkY2RiMDkzYWZlMWY1NWQ1ZjgxMjY2OTc=
12
+ data.tar.gz: !binary |-
13
+ MDMyZmM4MzZkYWNjNzk2NDcwNjkzY2M4ZWVjMzIwMmE1ODlkNzM5NGMzYjUx
14
+ N2FjMTUzZjJlZGQyYzkwMGJiYzI3YTY1ODhmMjQ3ZTIxZTFhNTM5YjRjMWVi
15
+ ODMxODY0Njg4Y2JjY2RmZWMwODk2Y2YwZGQ3MDI4YThiMjExN2U=
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Pavel Galeta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ file_sorter
2
+ ===========
3
+
4
+ Simple folder generator for you files or photos.
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ $:.unshift(File.dirname(__FILE__) + "/../lib")
6
+ require 'file_sorter'
7
+
8
+ path = (ARGV.shift || '')
9
+
10
+ puts "start sorting folder: #{path}"
11
+ FileSorter.start :folder => path
12
+ puts "end sorting folder: #{path}"
@@ -0,0 +1,17 @@
1
+ module FileSorter
2
+ autoload :Sorter, "file_sorter/sorter"
3
+
4
+ # FileSorter.start :folder => "/Volumes/Data/superp/www/gems/file_sorter/test"
5
+ #
6
+ def self.start(options={})
7
+ sorter = Sorter.new(options)
8
+ sorter.start
9
+ end
10
+
11
+ # FileSorter.revert :folder => "/Volumes/Data/superp/www/gems/file_sorter/test"
12
+ #
13
+ def self.revert(options={})
14
+ sorter = Sorter.new(options)
15
+ sorter.revert
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ require "fileutils"
2
+
3
+ module FileSorter
4
+ class Sorter
5
+ attr_accessor :folder, :format
6
+
7
+ def initialize(options = {})
8
+ @folder = options[:folder] || "."
9
+ @format = options[:format] || "%Y/%m/%d"
10
+ end
11
+
12
+ def start
13
+ Dir.foreach(@folder) do |file|
14
+ next if [".", ".."].include?(file)
15
+
16
+ full_path = File.join(@folder, file)
17
+ new_folder = File.join(@folder, File.mtime(full_path).strftime(@format))
18
+
19
+ FileUtils.mkdir_p new_folder
20
+ FileUtils.mv full_path, File.join(new_folder, file)
21
+ end
22
+ end
23
+
24
+ def revert
25
+ FileUtils.cd(@folder) do
26
+ Dir["**/*"].each do |item|
27
+ if File.file?(item)
28
+ FileUtils.mv item, File.join(@folder, File.basename(item))
29
+ end
30
+ end
31
+
32
+ Dir["**/*"].each do |item|
33
+ FileUtils.remove_dir(item) if File.directory?(item)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file_sorter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Galeta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple folder generator for you files or photos
14
+ email: superp1987@gmail.com
15
+ executables:
16
+ - file_sorter
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - bin/file_sorter
24
+ - lib/file_sorter.rb
25
+ - lib/file_sorter/sorter.rb
26
+ homepage: https://github.com/superp/file_sorter
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.2.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: File to folder sorter
50
+ test_files: []