organize_files 1.0.4 → 1.0.6
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.
- checksums.yaml +4 -4
- data/lib/organize_files/file_handler.rb +14 -4
- data/lib/organize_files/file_order.rb +8 -5
- data/lib/organize_files/organizer.rb +3 -1
- data/lib/organize_files/version.rb +1 -1
- data/organize_files.gemspec +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d27ae3cef81d53fa5078a2bc8c242d75062911576501387741e791c77a627e34
|
4
|
+
data.tar.gz: 9d59c802ec106dd90a7249ba76a21a6db35809b017f9c380eda9691e01ade4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e37d5b268ff4aa380d0880eae45aaa51b1bfab6c704ef2f0181f0aba567cc9a2b8b4246b0207951f71c5963dbbd4be604ff9afb8fc5ac23ec4b1bd724df9562
|
7
|
+
data.tar.gz: f9531503d1537d44caec79b46455aa57c6d6a6ae8ef82fa5e2f24828e5b8d77a521e0bd5b0112a89bddce5de4b8441377bdc1bf710c1487492904379adad9e46
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module OrganizeFiles
|
4
5
|
# file_handler.rb
|
@@ -8,14 +9,23 @@ module OrganizeFiles
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def scan_files
|
11
|
-
Dir.
|
12
|
+
Dir.new(@directory).children
|
12
13
|
end
|
13
14
|
|
14
15
|
def move_file(file, category)
|
15
|
-
|
16
|
+
source_path = File.join(@directory, file)
|
17
|
+
destination = File.join(@directory, category)
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
FileUtils.mkdir_p(destination) unless File.directory?(destination)
|
20
|
+
|
21
|
+
destination_path = File.join(destination, File.basename(source_path))
|
22
|
+
|
23
|
+
if File.exist?(source_path)
|
24
|
+
FileUtils.mv(source_path, destination_path)
|
25
|
+
puts "Successfully moved #{File.basename(source_path)} to #{destination_path}"
|
26
|
+
else
|
27
|
+
puts "File not found: #{source_path}"
|
28
|
+
end
|
19
29
|
end
|
20
30
|
|
21
31
|
def remove_empty_folders
|
@@ -4,11 +4,12 @@ module OrganizeFiles
|
|
4
4
|
# file_sorter.rb
|
5
5
|
class FileOrder
|
6
6
|
TYPES = {
|
7
|
-
images: ['.jpg', '.jpeg', '.png', '.gif'],
|
8
|
-
documents: ['.pdf', '.docx', '.txt', '.md'],
|
7
|
+
images: ['.jpg', '.jpeg', '.png', '.gif', '.avif'],
|
8
|
+
documents: ['.pdf', '.docx', '.txt', '.md', '.json', '.csv', '.xls', '.xlsx', '.ppt', '.pptx'],
|
9
9
|
audio: ['.mp3', '.wav', '.flac'],
|
10
10
|
videos: ['.mp4', '.mkv', '.avi'],
|
11
|
-
archives: ['.zip', '.tar', '.rar', '.gz']
|
11
|
+
archives: ['.zip', '.tar', '.rar', '.gz', '.7z', '.iso'],
|
12
|
+
apks: ['.apk']
|
12
13
|
}.freeze
|
13
14
|
|
14
15
|
def initialize(file)
|
@@ -16,14 +17,16 @@ module OrganizeFiles
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def categorize
|
19
|
-
file_ext = File.extname(file)
|
20
|
+
file_ext = File.extname(@file)
|
20
21
|
category = TYPES.find { |_key, exts| exts.include?(file_ext) }
|
22
|
+
return 'Archives' unless category
|
21
23
|
|
22
|
-
case category
|
24
|
+
case category[0]
|
23
25
|
when :images then 'Pictures'
|
24
26
|
when :documents then 'Documents'
|
25
27
|
when :audio then 'Music'
|
26
28
|
when :videos then 'Videos'
|
29
|
+
when :apks then 'Apks'
|
27
30
|
else
|
28
31
|
'Archives'
|
29
32
|
end
|
@@ -15,9 +15,11 @@ module OrganizeFiles
|
|
15
15
|
|
16
16
|
def organize
|
17
17
|
@file_handler.scan_files.each do |file|
|
18
|
-
|
18
|
+
next if File.directory?(file)
|
19
19
|
|
20
|
+
categorize_file = OrganizeFiles::FileOrder.new(file).categorize
|
20
21
|
@file_handler.move_file(file, categorize_file)
|
22
|
+
@file_handler.remove_empty_folders
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/organize_files.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: organize_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mayank Agnihotri
|
@@ -43,7 +43,7 @@ files:
|
|
43
43
|
- lib/organize_files/organizer.rb
|
44
44
|
- lib/organize_files/version.rb
|
45
45
|
- organize_files.gemspec
|
46
|
-
homepage:
|
46
|
+
homepage: https://github.com/mayankagnihotri7/file-organizer
|
47
47
|
licenses:
|
48
48
|
- MIT
|
49
49
|
metadata: {}
|