New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

filename_increment

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filename_increment

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

filename_increment

Please consider starring the project to show your heart and support.

Project is based on this repo, show him some love please ;).

When copying or moving files, it's common for operating systems to automatically add an increment or 'copy' to duplicate file names. This does that for Ruby applications, with automatic platform detection and support for Linux, MacOs, and Windows conventions.

Installation

Add this line to your application's Gemfile:

gem 'filename_increment'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install filename_increment

Usage

All methods automatically detect the platform to use, unless platform is defined on the options.

FilenameIncrement.new('foo/bar.txt', platform: 'linux').to_s
# foo/bar (copy).txt
FilenameIncrement.new('foo/bar.txt', platform: 'win32').to_s
# foo/bar (2).txt
FilenameIncrement.new('foo/bar.txt', platform: 'darwin').to_s
# foo/bar copy.txt

Options

options.fs

Description: Check the file system, and automatically increment the file based on existing files. Thus, if the file name is foo.txt, and foo (2).txt already exists, the file will automatically be renamed to foo (3).txt.

Also uses the correct conventions for Linux, Windows (win32), and MacOS (darwin).

Type: boolean

Default: nil

options.platform

Description: Specify the platform conventions to use.

Type: String

Default: Uses Gem::Platform.local.os. Valid values are linux, win32 and darwin.

Operating Systems

Supported Operating Systems

Currently Windows, Darwin (MacOS), and Linux are supported. This library attempts to automatically use the correct conventions for each operating system. Please create an issue if you ecounter a bug.

If you use an operating system with different conventions, and you would like for this library to add support, please create an issue with a detailed description of those conventions, or feel free to do a pull request.

Linux

When a file is copied or moved, and the destination file path already exists, Linux uses the following conventions for incrementing the file name.

Source pathDestination pathTypeDirectory1
foo.txtfoo (copy).txt, foo (another copy).txt, foo (3rd copy).txt, ...fileSame directory as source
foofoo (copy), foo (another copy), foo (3rd copy), ...directorySame directory as source

1 On Linux, when a file or folder is copied or moved to a different directory and another file or folder with the same name exists in that directory, you are prompted to choose a new name for the file or folder, or to cancel or skip the operation.

MacOS

When a file is copied or moved, and the destination file path already exists, MacOS uses the following conventions for incrementing the file name.

Source pathDestination pathTypeDirectory1
foo.txtfoo copy.txt, foo copy 2.txt, ...fileSame directory as source
foo.txtfoo 2.txt, foo 3.txt, ...fileDifferent directory than source
foofoo copy, foo copy 2, ...directorySame directory as source

1 MacOS uses different conventions for incrementing file names when the source file is copied, moved or renamed to a different directory, versus when the file is copied into the same directory.

Windows

When a file is copied or moved, and the destination file path already exists, Windows uses the following conventions for incrementing the file name.

Source pathDestination pathTypeDirectory1
foo.txtfoo - Copy.txtfileSame directory as source
foo.txtfoo (2).txtfileDifferent directory than source
foo (2).txtfoo (3).txtfileDifferent directory than source
foofoo - CopydirectorySame directory as source
foo - Copyfoo - Copy (2)directorySame directory as source

1 Windows uses different conventions for incrementing file names when the source file is copied, moved or renamed to a different directory, versus when the file is copied into the same directory. Also, when a folder is copied to a new directory, and the new directory already has a folder with the same name, Windows just merges the folders automatically.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the FilenameIncrement project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

FAQs

Package last updated on 03 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc