mass_rename 1.0.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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +30 -0
- data/.travis.yml +12 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/mass_rename +5 -0
- data/lib/mass_rename/version.rb +5 -0
- data/lib/mass_rename.rb +79 -0
- data/mass_rename.gemspec +28 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67811d7df2574827a308984a745bec79c8130b78
|
4
|
+
data.tar.gz: 51c7ee70bb86e67346f7d99b7cc3567a02be92ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e385312a95ded03ab02b0cabdb9bf700e2359f88a0fadf2f79ca9f1973efc1e5cae6d6e8107b7762dfcb9b74166e149f1bb2cc7f15bf5995bd421b5fe28c13b5
|
7
|
+
data.tar.gz: 85c3af91e51876ae4bae69c6dca1871313f10f38510d8d79270f6430d06754f83fa87111302d86c2a270e7e2a8d556068815ac8b87267a242ea47192eef982ba
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-09-22 22:01:45 -0700 using RuboCop version 0.50.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Max: 35
|
13
|
+
|
14
|
+
# Offense count: 6
|
15
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
16
|
+
# URISchemes: http, https
|
17
|
+
Metrics/LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: CountComments.
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 15
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
Style/Documentation:
|
27
|
+
Exclude:
|
28
|
+
- 'spec/**/*'
|
29
|
+
- 'test/**/*'
|
30
|
+
- 'lib/mass_rename.rb'
|
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 2.4
|
6
|
+
|
7
|
+
notifications:
|
8
|
+
email:
|
9
|
+
recipients:
|
10
|
+
- secure: "BIcuEkLfJjpVKlkmjvUR21zrS+7Q1aYsurjZmIHauR0PDl0K7XmoNQtz09b4Ee+1hVzLV3gScDmUYpeVTWE7erBBZVYnNcSV2zIV4sVtAiCx2Aoi9xpGOVb+vop4o89+2RLzy2Wp9dFfcE1C5/IVytvFdS7x4ERFS7SgjzT7M2kS0L2mpGQg7ykky97HdjyjFuEGHfcN2B9gm+U5EQDFRfAeNkHeC4R3jygwsMGq1nhUeiAgzqaHRx+jcwe0NLgoEuw/fN3GJ5VosvxjqIx70sjJQayN8NvRmmaMLVWa1TZxBSV548O9CVlsxJNvERNneDhex83OYBPL/YfPxUkVGiufGI8TWnkQZJSOylnZN3F2BL2wURLyOIK1w/DYlWykLCcJpVKHBt6pw0VZ8Y1ZPgjDmlJxS5NRRyuRNcgTYhZt1ShRr9QlzMcZzTE4vJfHJ5dmIMWGHPSOyy1434vlYvAPK7yXGOquSIYqDPCsZ0Eu15ShwSp728eJraBBGY1GDYPlXeluescq3PmSpuTZCdAxXKdmHT4BsEi4Jrax64DBpfiBXMHLWeid+6sxOHxN6A3Ehdhy2Tt8gdJJDex6Bx9qVAPx91Scm3knw+4zpeOjAZPcQdPl+CN/zX0wQWuDbrBCpEsZYU6rToJH9xtQ8bI3OvI8AYWYGrrpDN/Txzs="
|
11
|
+
on_success: never
|
12
|
+
on_failure: always
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Lucas Street
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# mass_rename
|
2
|
+
[](https://travis-ci.org/lucis-fluxum/mass_rename) [](https://codecov.io/gh/lucis-fluxum/mass_rename)
|
3
|
+
|
4
|
+
Filter and mass rename files in a directory or subdirectories with regular expressions.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'mass_rename', git: 'https://github.com/lucis-fluxum/mass_rename.git'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Usage: mass_rename [options]
|
21
|
+
-d, --dir NAME Select a different working directory
|
22
|
+
-f, --filter PATTERN Filter files using a regular expression
|
23
|
+
-r, --replace PATTERN Replace matched file names with a replacement string
|
24
|
+
--recursive Select files in the target directory and all its subdirectories
|
25
|
+
-v, --version Display version
|
26
|
+
-h, --help Print this help
|
27
|
+
|
28
|
+
The following example will recursively rename files matching the pattern "some_file_pattern_(\d)", capture the digit character,
|
29
|
+
and rename all matching files with the replacement "\1_new_name", substituting the captured digit for "\1".
|
30
|
+
```
|
31
|
+
mass_rename --recursive -d target_dir -f "some_file_pattern_(\d)" -r "\1_new_name"
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
37
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lucis-fluxum/mass_rename.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'mass_rename'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/mass_rename
ADDED
data/lib/mass_rename.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'mass_rename/version'
|
7
|
+
|
8
|
+
module MassRename
|
9
|
+
# Processes the provided options from the command line.
|
10
|
+
# Usage and effects for different options are given by running the script with the '-h' flag.
|
11
|
+
#
|
12
|
+
# @param args [Array] the arguments to the CLI
|
13
|
+
# @return [Hash] the arguments as a hash
|
14
|
+
def self.process_options(args)
|
15
|
+
options = {}
|
16
|
+
OptionParser.new do |parser|
|
17
|
+
parser.banner = 'Usage: mass_rename [options]'
|
18
|
+
|
19
|
+
parser.on('-d', '--dir NAME', 'Select a different working directory') do |dir_name|
|
20
|
+
options[:directory] = dir_name
|
21
|
+
end
|
22
|
+
|
23
|
+
parser.on('-f', '--filter PATTERN', 'Filter files using a regular expression') do |regex|
|
24
|
+
options[:filter] = Regexp.new(regex)
|
25
|
+
end
|
26
|
+
|
27
|
+
parser.on('-r', '--replace PATTERN', 'Replace matched file names with a replacement string') do |replacement|
|
28
|
+
options[:replacement] = replacement
|
29
|
+
end
|
30
|
+
|
31
|
+
parser.on('--recursive', 'Select files in the target directory and all its subdirectories') do |recursive|
|
32
|
+
options[:recursive] = recursive
|
33
|
+
end
|
34
|
+
|
35
|
+
parser.on('-v', '--version', 'Display version') do
|
36
|
+
puts MassRename::VERSION
|
37
|
+
end
|
38
|
+
|
39
|
+
parser.on('-h', '--help', 'Print this help') do
|
40
|
+
puts parser
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.parse!(args)
|
44
|
+
end
|
45
|
+
options
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns a list of file names matching a pattern, optionally recursive.
|
49
|
+
#
|
50
|
+
# @param options [Hash] the options returned by {MassRename#process_options}
|
51
|
+
# @return [Array<String>] the files matching the filter
|
52
|
+
def self.file_list(options)
|
53
|
+
Dir.glob(options[:recursive] ? '**/*' : '*').select do |path|
|
54
|
+
path =~ options[:filter]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Renames a file according to a pattern. The format of the replacement pattern is what you'd
|
59
|
+
# pass to +String#gsub+.
|
60
|
+
#
|
61
|
+
# @param path [String] the path of the file to rename
|
62
|
+
# @param options [Hash] the options returned by {MassRename#process_options}
|
63
|
+
def self.rename(path, options)
|
64
|
+
new_path = path.gsub(options[:filter], options[:replacement])
|
65
|
+
FileUtils.mv(path, new_path)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Main entry point for this library. Processes the given options and then renames files
|
69
|
+
# matching the filter according to the given replacement string.
|
70
|
+
#
|
71
|
+
# @param args [Array<String>] arguments to parse. Equal to ARGV if you're not doing anything fancy.
|
72
|
+
def self.run(args)
|
73
|
+
options = MassRename.process_options(args)
|
74
|
+
Dir.chdir(options[:directory]) if options[:directory]
|
75
|
+
MassRename.file_list(options).each do |path|
|
76
|
+
MassRename.rename(path, options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/mass_rename.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/mass_rename/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mass_rename'
|
7
|
+
spec.version = MassRename::VERSION
|
8
|
+
spec.author = 'Luc Street'
|
9
|
+
spec.summary = 'Mass rename files.'
|
10
|
+
spec.description = 'Filter and rename multiple files in a directory or subdirectories with regular expressions.'
|
11
|
+
spec.homepage = 'https://github.com/lucis-fluxum/mass_rename'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.required_ruby_version = '>= 1.9'
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
|
20
|
+
spec.metadata['yard.run'] = 'yri'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
spec.add_development_dependency 'codecov'
|
27
|
+
spec.add_development_dependency 'yard'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mass_rename
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luc Street
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Filter and rename multiple files in a directory or subdirectories with
|
98
|
+
regular expressions.
|
99
|
+
email:
|
100
|
+
executables:
|
101
|
+
- mass_rename
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".rubocop_todo.yml"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/mass_rename
|
117
|
+
- lib/mass_rename.rb
|
118
|
+
- lib/mass_rename/version.rb
|
119
|
+
- mass_rename.gemspec
|
120
|
+
homepage: https://github.com/lucis-fluxum/mass_rename
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata:
|
124
|
+
yard.run: yri
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.9'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.6.13
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Mass rename files.
|
145
|
+
test_files: []
|