organize_files 1.0.4 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3061ecd6ef9179919bcb4f1b8a01fe315d10bfb17cb1b3db41520783edd84b00
4
- data.tar.gz: 938d5d4ac23fbef82b1419bf39736f06f66c2ba270ebb4322d4108018403904a
3
+ metadata.gz: 75a8fdb1af963db3364f72e4abfcbebd4ebd1f4a30681bdef55df08663e8e72e
4
+ data.tar.gz: f67dade0a8a14066ecf0506c6f0a1f2936a2c8e6c43bf4c8513f0a9d6a5391e7
5
5
  SHA512:
6
- metadata.gz: e21de4fbb0c5b87eaef0324628da5aaee4834bbe8edad929431871da8051ee773fcf0308bbbae1da742a2916a8315ad3f9973b457389a1f89f0b03190e30e402
7
- data.tar.gz: f1284aec10dc908c5616057e99ed6c2c6f80d3e6df398120d780142b2d35244d8843d1633aa41824c9ce6a95dd4e25c3a325a307739495324cf0db1567d50ad1
6
+ metadata.gz: 6fc5e6791cb3b4cc7af8dddcaefa654bfb39704e314433419401de0b2da02ab8b6110ec83271fdbb20715853e93f5dc7edcb4b13ac316e42516664a271812696
7
+ data.tar.gz: e51182a547b2b24697594a379d9d47b874b611832dfd83f4002f2bd28f32422c48ee6c0074bb61a5c83d2767afe247a572647af46e0661ff1d71b35ffb5970ed
@@ -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.entries(@directory).reject { |file| file.start_with?('.') }
12
+ Dir.new(@directory).children
12
13
  end
13
14
 
14
15
  def move_file(file, category)
15
- destination = File.join(@destination, category)
16
+ source_path = File.join(@directory, file)
17
+ destination = File.join(@directory, category)
16
18
 
17
- Dir.mkdir(destination) unless Dir.exist?(destination)
18
- FileUtils.mv(file, destination)
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
- categorize_file = OrganizeFiles::FileOrder.new(file).categorize
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrganizeFiles
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
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
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mayank Agnihotri