organize_files 1.0.8 → 1.1.0
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/Gemfile +3 -1
- data/README.md +68 -6
- data/lib/organize_files/file_handler.rb +1 -2
- data/lib/organize_files/file_order.rb +25 -20
- data/lib/organize_files/organizer.rb +10 -14
- data/lib/organize_files/version.rb +1 -1
- data/lib/organize_files.rb +6 -3
- data/organize_files.gemspec +19 -13
- metadata +38 -12
- data/bin/organize_files +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be274b8e715cec0eeebd8fd07dc882d86a3c7ce3576b4be5ffbbdb873581b929
|
4
|
+
data.tar.gz: 28ccb608bd713032fa209bb9b301bbd6bcf4bc99b383f179bc7b963fe4d4cdbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcbab96c30fcc3be8e4b9db3bb6b125647e3b9798bb45faa8c1bbcfeaf3c6ec11c6dfed0e47279ffb03797ebc9489534ea9517bf1e8cdd58346af5b021cd0c36
|
7
|
+
data.tar.gz: 98106cd82b28ed14543d6e3b098883effb9af21c67f478aed3cdf0c563b21308fd045c45e31bbc489453e16ddf02393252ff455a467df90314e7f14a66c0bb90
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,79 @@
|
|
1
1
|
# OrganizeFiles
|
2
2
|
|
3
|
-
|
3
|
+
Decluttering your file system doesn’t have to be a hassle anymore. Moving files into their appropriate folders can be tedious and time-consuming—especially when done manually.
|
4
|
+
|
5
|
+
The Organize Files gem for Ruby streamlines this process by automatically organizing files based on their extensions. Simply point it to a directory, and it will sort the files into their respective folders. If a folder for a specific file extension doesn't already exist, it will be created for you.
|
4
6
|
|
5
7
|
## Getting started
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
Install the gem
|
10
|
+
```bash
|
11
|
+
gem install organize_files
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Enter the directory you want to sort the files in.
|
17
|
+
|
18
|
+
```bash
|
19
|
+
organize_files [options] <directory>
|
20
|
+
```
|
21
|
+
- <directory> The directory you want to organize
|
22
|
+
|
23
|
+
Example:
|
24
|
+
```bash
|
25
|
+
organize_files '/path/to/downloads'
|
26
|
+
```
|
27
|
+
|
28
|
+
Output:
|
29
|
+
```bash
|
30
|
+
Successfully moved index2.pdf to /path/to/downloads/Documents/index2.pdf
|
31
|
+
```
|
32
|
+
|
33
|
+
Options:
|
34
|
+
- `-c`, `--config`, CONFIG_FILE: Specify the configuration file to use.
|
35
|
+
|
36
|
+
- If not provided, the script will look for `~/.organize_config.yml` in your home directory.
|
37
|
+
- If ~/.organize_config.yml is not found, it will use the built-in default configuration.
|
38
|
+
- `-h`, `--help`, Prints this help message.
|
39
|
+
|
40
|
+
|
41
|
+
## Configuration
|
42
|
+
You can customize how files are categorized by creating a YAML configuration file.
|
43
|
+
|
44
|
+
Default Configuration File:
|
45
|
+
|
46
|
+
The script will automatically look for a configuration file named ~/.organize_config.yml in your home directory.
|
47
|
+
|
48
|
+
Example ~/.organize_config.yml:
|
49
|
+
|
50
|
+
```YAML
|
51
|
+
images:
|
52
|
+
- .jpg
|
53
|
+
- .jpeg
|
54
|
+
- .png
|
55
|
+
documents:
|
56
|
+
- .pdf
|
57
|
+
- .docx
|
58
|
+
- .txt
|
59
|
+
audio:
|
60
|
+
- .mp3
|
61
|
+
- .wav
|
62
|
+
videos:
|
63
|
+
- .mp4
|
64
|
+
- .mov
|
65
|
+
archives:
|
66
|
+
- .zip
|
67
|
+
- .rar
|
68
|
+
programming:
|
69
|
+
- .rb
|
70
|
+
- .py
|
71
|
+
- .js
|
72
|
+
```
|
11
73
|
|
12
74
|
### Requirements
|
13
75
|
|
14
76
|
This gem requires Ruby 3.0+.
|
15
77
|
|
16
78
|
## Contributing
|
17
|
-
Please see [CONTRIBUTING.md](CONTRIBUTING.md)
|
79
|
+
Please see [CONTRIBUTING.md](CONTRIBUTING.md)
|
@@ -1,35 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module OrganizeFiles
|
4
|
-
# file_sorter.rb
|
5
4
|
class FileOrder
|
6
|
-
|
7
|
-
images: ['.jpg', '.jpeg', '.png', '.gif', '.avif'],
|
8
|
-
documents: ['.pdf', '.docx', '.txt', '.md', '.json', '.csv', '.xls', '.xlsx', '.ppt', '.pptx'],
|
9
|
-
audio: ['.mp3', '.wav', '.flac'],
|
10
|
-
videos: ['.mp4', '.mkv', '.avi'],
|
11
|
-
archives: ['.zip', '.tar', '.rar', '.gz', '.7z', '.iso'],
|
12
|
-
apks: ['.apk']
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
def initialize(file)
|
5
|
+
def initialize(file, config_file = nil)
|
16
6
|
@file = file
|
7
|
+
@config_file = config_file || "~/.organize_config.yml"
|
8
|
+
@types = load_config
|
17
9
|
end
|
18
10
|
|
19
11
|
def categorize
|
20
12
|
file_ext = File.extname(@file)
|
21
|
-
category =
|
22
|
-
return
|
13
|
+
category = @types.find { |_key, exts| exts.include?(file_ext) }
|
14
|
+
return "Miscellaneous" unless category
|
15
|
+
|
16
|
+
category[0].to_s.capitalize
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
when :apks then 'Apks'
|
19
|
+
private
|
20
|
+
|
21
|
+
def load_config
|
22
|
+
if File.exist?(@config_file)
|
23
|
+
YAML.load_file(@config_file)
|
30
24
|
else
|
31
|
-
|
25
|
+
default_config
|
32
26
|
end
|
33
27
|
end
|
28
|
+
|
29
|
+
def default_config
|
30
|
+
{
|
31
|
+
pictures: [".jpg", ".jpeg", ".png", ".gif", ".avif"],
|
32
|
+
documents: [".pdf", ".docx", ".txt", ".md", ".json", ".csv", ".xls", ".xlsx", ".ppt", ".pptx"],
|
33
|
+
music: [".mp3", ".wav", ".flac"],
|
34
|
+
videos: [".mp4", ".mkv", ".avi"],
|
35
|
+
archives: [".zip", ".tar", ".rar", ".gz", ".7z", ".iso"],
|
36
|
+
apks: [".apk"]
|
37
|
+
}
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
@@ -1,36 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'file_handler'
|
4
|
-
require_relative 'file_order'
|
5
|
-
|
6
3
|
module OrganizeFiles
|
7
|
-
# organizer.rb
|
8
4
|
class Organizer
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
5
|
+
def initialize(options)
|
6
|
+
@directory = options[:directory]
|
7
|
+
@config = options[:config]
|
8
|
+
@file_handler = FileHandler.new(@directory)
|
9
|
+
@ignore_empty_directory = options[:ignore_empty_directory]
|
14
10
|
end
|
15
11
|
|
16
12
|
def organize
|
17
13
|
@file_handler.scan_files.each do |file|
|
18
14
|
next if file_directory?(file)
|
19
15
|
|
20
|
-
categorize_file =
|
16
|
+
categorize_file = FileOrder.new(file, @config).categorize
|
21
17
|
@file_handler.move_file(file, categorize_file)
|
22
|
-
@file_handler.remove_empty_folders
|
23
18
|
end
|
19
|
+
@file_handler.remove_empty_folders unless @ignore_empty_directory
|
24
20
|
end
|
25
21
|
|
26
22
|
private
|
27
23
|
|
28
24
|
def file_directory?(file)
|
29
|
-
|
25
|
+
directories = []
|
30
26
|
expanded_file_path = File.expand_path(file, @directory)
|
31
|
-
File.directory?(expanded_file_path) &&
|
27
|
+
File.directory?(expanded_file_path) && directories << expanded_file_path
|
32
28
|
|
33
|
-
!
|
29
|
+
!directories.empty?
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
data/lib/organize_files.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "zeitwerk"
|
4
|
+
require "yaml"
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
module OrganizeFiles
|
7
|
+
@loader = Zeitwerk::Loader.for_gem
|
8
|
+
@loader.setup
|
9
|
+
end
|
data/organize_files.gemspec
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("lib/organize_files/version", __dir__)
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
-
s.authors = [
|
6
|
+
s.name = "organize_files"
|
7
|
+
s.authors = ["Mayank Agnihotri"]
|
8
8
|
s.version = OrganizeFiles::VERSION
|
9
|
-
s.files = Dir[
|
10
|
-
|
11
|
-
s.licenses = [
|
12
|
-
s.summary =
|
9
|
+
s.files = Dir["README.md", "LICENSE", "CHANGELOG.md", "lib/**/*.rb", "lib/**/*.rake", "organize_files.gemspec",
|
10
|
+
".github/*.md", "Gemfile", "Rakefile", "CONTRIBUTING.md"]
|
11
|
+
s.licenses = ["MIT"]
|
12
|
+
s.summary = "Organize files into their own separate folders"
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
|
-
s.required_ruby_version =
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
s.
|
17
|
-
|
18
|
-
s.
|
14
|
+
s.required_ruby_version = ">= 3.1.4"
|
15
|
+
s.extra_rdoc_files = ["README.md"]
|
16
|
+
s.add_dependency "zeitwerk", "~> 2.4"
|
17
|
+
|
18
|
+
s.add_development_dependency "rspec"
|
19
|
+
s.add_development_dependency "rubocop", "~> 1.68"
|
20
|
+
|
21
|
+
s.bindir = "exe"
|
22
|
+
s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
23
|
+
s.homepage = "https://github.com/mayankagnihotri7/file-organizer"
|
24
|
+
|
19
25
|
s.metadata = {
|
20
|
-
|
26
|
+
"source_code_uri" => "https://github.com/mayankagnihotri7/file-organizer"
|
21
27
|
}
|
22
28
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mayank Agnihotri
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zeitwerk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rubocop
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,10 +52,9 @@ dependencies:
|
|
24
52
|
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '1.68'
|
27
|
-
description:
|
28
|
-
email:
|
29
|
-
executables:
|
30
|
-
- organize_files
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
executables: []
|
31
58
|
extensions: []
|
32
59
|
extra_rdoc_files:
|
33
60
|
- README.md
|
@@ -36,7 +63,6 @@ files:
|
|
36
63
|
- Gemfile
|
37
64
|
- LICENSE
|
38
65
|
- README.md
|
39
|
-
- bin/organize_files
|
40
66
|
- lib/organize_files.rb
|
41
67
|
- lib/organize_files/file_handler.rb
|
42
68
|
- lib/organize_files/file_order.rb
|
@@ -48,7 +74,7 @@ licenses:
|
|
48
74
|
- MIT
|
49
75
|
metadata:
|
50
76
|
source_code_uri: https://github.com/mayankagnihotri7/file-organizer
|
51
|
-
post_install_message:
|
77
|
+
post_install_message:
|
52
78
|
rdoc_options: []
|
53
79
|
require_paths:
|
54
80
|
- lib
|
@@ -63,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
89
|
- !ruby/object:Gem::Version
|
64
90
|
version: '0'
|
65
91
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
67
|
-
signing_key:
|
92
|
+
rubygems_version: 3.4.1
|
93
|
+
signing_key:
|
68
94
|
specification_version: 4
|
69
95
|
summary: Organize files into their own separate folders
|
70
96
|
test_files: []
|
data/bin/organize_files
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require 'organize_files'
|
5
|
-
|
6
|
-
options = {}
|
7
|
-
OptionParser.new do |opts|
|
8
|
-
opts.banner = 'Usage: organize_files [options]'
|
9
|
-
|
10
|
-
opts.on('-d', '--directory DIRECTORY', 'Directory to organize') do |directory|
|
11
|
-
options[:directory] = directory
|
12
|
-
end
|
13
|
-
|
14
|
-
opts.on('-h', '--help', 'Prints this help') do
|
15
|
-
puts opts
|
16
|
-
exit
|
17
|
-
end
|
18
|
-
end.parse!
|
19
|
-
|
20
|
-
if options[:directory].nil?
|
21
|
-
puts 'You must specify a directory to organize'
|
22
|
-
exit 1
|
23
|
-
end
|
24
|
-
|
25
|
-
sorter = OrganizeFiles::Organizer.new(options[:directory])
|
26
|
-
sorter.organize
|
27
|
-
|
28
|
-
puts "Files in '#{options[:directory]}' have been organized"
|