Giter VIP home page Giter VIP logo

renamer's Issues

Dry-run doesn't log anything

I see there is already an issue with almost this title, but that was probably for the previous version. Looking at the source-code, I don't know how dry-run could log any output, because the dryRunLog from rename-file.js is written to, but never read.

--git flag?

Thoughts on providing a --git flag (name WIP) to the cli that would run git instead of fs here? Would need to solve for elegantly running a git command in node but would be helpful.

Scenario: I have to rename a ton of files in a git repo but i need to use git mv so i don't lose history.

I would be open to building this, just wanted to get initial thoughts and if it sounds like something you would like to add, any suggestions/requirements come to mind?

using renamer programmatically

Is there any way to use this tool programmatically in node.js?
for example:

var renamer = require('renamer');
renamer('this', 'that', '*.js');

Make the resulting operation (e.g. rename, copy, git mv etc) user-definable

Might be a bit outside of project scope, but hear me out

I would love to have a library, that would have same usage / api / plugin support, but creating copies of files instead
Basically, just additional cli flag or interchangeable fork of renamer instead, if you think that this functionality would not belong here

I'm willing to do this by myself, but wanna hear contributors ideas first

option to only log summary

As we do use renamer for every build, its not needed to log every single renamed file,
instead show a one line, e.g. how many files were renamed, as it clutters the log.

What do you think?

btw. nice tool!

Broken on node v12

Fails to load plugins when using node v12.4.0.

$ renamer
Cannot find module 'default'
Require stack:
- /usr/local/lib/node_modules/renamer/node_modules/load-module/index.js
- /usr/local/lib/node_modules/renamer/node_modules/command-line-plugin/index.js
- /usr/local/lib/node_modules/renamer/lib/cli-app.js
- /usr/local/lib/node_modules/renamer/bin/cli.js

Globbing doesn't do recursion

To get recursion, I have to add an additional /** per directory level. So for a directory nested four levels in, I have to target **/**/**/**. Is this expected behavior? I'm on Windows, but I do everything in the bash - globbing always works as expected.

Regexp finishes after first group

Trying to do a command like:
renamer --find '/([^\.]+)\.[^\.]+\.(\w+)/' --replace '$1.$2' build/static/media

file that it should apply is test.3af24c.jpg

Renamer version 1.1.0

Getting error:
\.[\.]+\.(\w+)$/i' was unexpected at this time.

It seems to finish after first group and not continue with regexp.

Am I missing something ?

Preset the naming method of some files or directories?

Preset some naming schemes?

  • camel: foo barfooBar
  • pascal: foo barFooBar
  • constant: foo barFOO_BAR
  • dot: foo barfoo.bar
  • kebab: foo barfoo-bar
  • snake: foo barfoo_bar
  • title: foo barFoo Bar
  • lower: FOO BARfoo bar
  • upper: foo barFOO BAR

make more hackable

make easy to insert additional functions into pipeline.. .use(middleware) type approach?

Can't able use it as global node package

Hi,

First of all Thanks for this awesome package.

It works well with local node_modules in renaming multiple files with a JavaScript file for renaming.

But i wanted to rename files without installing package locally, but in global installation with
npm i global renamer
this installed renamer globally, but when run the renaming script in any folder which doesn't have renamer package installed locally is not working.

here is the script i am using to rename files.

/* eslint-disable */
const Renamer = require('renamer')
const renamer = new Renamer()

renamer.on('replace-result', replaceResult => {
  console.log(replaceResult)
})

renamer.rename({
  // files: [ '0*!(node_modules|code|temp)/**' ],
  files: ['**/*.m4v'],
  find: /(.*)(-\d+)/,
  replace: `$1`,
  dryRun: false
})

Please let me know if this can used as global npm package or not.

Note: I am using the above script as saved in a js file and run using node ./rename.js

Thanks in advance.

Ability to specify an order for renaming files

Hi there! Thanks for this awesome lib 😄

I'm trying to prefix files in a folder with indexes but I would like to be able to do it in a specific order, e.g.: in order of size, addition date, etc...

I would be willing to work in such a feature and submit a PR if you think it's a good idea! I believe we could use Node's fs.Stats Class properties to be able to specify an order-by property and do the ordering before mapping over the files array.

What do you think about this?

Windows: wrong behavior when using regular expression

Initial folders structure

.
├── aaa
│   └── aaa_inner
├── bbb
│   └── bbb_inner
├── ccc
│   └── ccc_inner

I run

renamer --find --regex * --replace 1 'aaa/**/*'

I got

.
├── 1
│   └── ccc_inner
├── aaa
│   └── 1
├── bbb
│   └── bbb_inner

I expected

.
├── aaa
│   └── 1
├── bbb
│   └── bbb_inner
├── ccc
│   └── ccc_inner

Unable to replace with a dash involved

This command fails:

renamer --find '_Small' --replace '-sm'

because it thinks -sm is another command line flag that it doesn't recognize. I assume this is actually an issue with what library you're using for argument parsing, but I thought you would want to know, as there are plenty of other argument parsers to choose from. Here's the output:

screen shot 2016-02-22 at 12 16 42 pm

As you can see, it confuses the program a bit.

Dry-run doesn't output anything

Hello,

I'm trying to use renamer without success.
So, I tried with dry-run option, but it doesn't report anything like:

  • the folder where it tries to search
  • the files it found or try to find

Is there a way to verbose the output to know what it is doing ?

Thanks in advance for your help.

_

_

--js expression and {{js}} token

e.g.

$ renamer -f file -r 'file{{js}}' --js Date.now() * 
$ renamer -f file -r '{{js}}-file' --js process.cwd() * 
$ renamer -r '{{js}}.txt' --js sprintf("%10s", index) * 
#0000000001.txt
#0000000002.txt
# etc

$ renamer -r '{{index}} ({{js}}).txt' --js moment(new Date()).fromNow() * 
#1 (1 Day ago).txt
#2 (4 Months ago).txt

$ renamer -f '(\w+) -r '{{js}}' --js '$1.toTitleCase()' * 
# filename.txt -> Filename.txt

Error with files starting with "." (dot)

Version: probably the latest as I have ran npm i -g renamer
Platform: Windows 10
Steps to reproduce:

mkdir temp; cd temp
touch .foo.bar
renamer -f "." ./* -d
# ERROR: These paths or patterns do not exist: ./*
renamer -f "/^\./" ./* -d
# ERROR: These paths or patterns do not exist: ./*
mv .foo.bar foo.bar
renamer -f "."  ./* -d
# No Error

PS: Thank you for making this awesome app!

Folder index replace in reverse order

This issue might be an extension of #31 or a bug of the current code.

I needed to rename folders using {{index}}, and I don't know if the current code has a bug because it incorrectly sorts the folders in descending order instead of ascending order (which is the correct order). This only happens in renaming folders, but it works fine when renaming files.

I'm using this command:

renamer --replace '{{index}}' *

When renaming (text) files, it correctly produce:

IMG_5776.txt -> 1
IMG_5777.txt -> 2
IMG_5778.txt -> 3

But with folders it happens the following:

IMG_5778 -> 1
IMG_5777 -> 2
IMG_5776 -> 3

To fix temporarily my issue to rename folders correctly I changed this line (https://github.com/75lb/renamer/blob/master/lib/renamer.js#L59):

results.list = options.files.map(replaceSingle.bind(null, findRegex, options.replace))

to

results.list = options.files.reverse().map(replaceSingle.bind(null, findRegex, options.replace))

But this would obviously brake the functionality of files renaming using index. @75lb Would be nice is this issue would be address. Thanks

Add ability to set index root

By default, the incrementing number which replaces the {{index}} token begins at 1. It would be good if you could override this initial value with --index-root.

Adding Suffix

I'm trying to use Renamer to add a 16-17 suffix to all files and folders, recursively as the files go several levels deep.

$ renamer --regex --find '([^.]+)\.(.*?)' --replace '$1 16-17.$2' '**'

seems to work for files, but I haven't been able to come up with a solution for folders that doesn't also affect files, after the extension.

Suggestions/advice would be greatly appreciated.

Restart index in each folder?

Is there a way to restart the index in each folder?

$ renamer --replace 'Image{{index}}.jpg' **/*.jpg
BeforeAfter
.
├── IMG_5776.JPG
├── IMG_5778.JPG
├── pics1
    ├── IMG_5792.JPG
    └── IMG_5795.JPG
└── pics2
    ├── IMG_5786.JPG
    └── IMG_5798.JPG
.
├── Image1.jpg
├── Image2.jpg
├── pics1
    ├── Image1.jpg
    └── Image2.jpg
└── pics2
    ├── Image1.jpg
    └── Image2.jpg

Can't able to add exclude directory in files options Array

Hi,

I was trying to use renamer to rename files programatically using this code

/* eslint-disable */
const Renamer = require('renamer')
const renamer = new Renamer()

renamer.on('replace-result', replaceResult => {
console.log(replaceResult)
})
let findString = new RegExp(('%d'));
let replaceString = new RegExp('$1')
renamer.rename({
files: [ './**/*' ],
find: /(\d+)/,
replace: ``,
dryRun: true
})

It does renaming the files inside node_modules also. I want to rename files but not in node_modules.

Please help me something to exclude the directories which i don't want to rename.

Thanks in advance.

escaping hifen

I'm trying to trim minified files that have "-min" at the the end of their name.
i'm using this command: renamer -d --find "-min" *
the problem is renamer is taking -m as an option and obviously fails with unkown option error.
I've tried to escape the hiphen with ^ but it doesnt work...

creating an alias that calls simple renaming

renamer --regex --find '(^..).*' --replace '$1.tex' * 

is the expression that i want to use.
but for the life of me i can't figure out how i would have to create this as an alias/ bash / zsh script.

alias renamer_help="renamer --help" 

works but
when i do thse same with the expression above.
my shell i telling me that

.zshrc:119: renamer --regex --find '(^..).*' --replace '$1.tex' * not found

I basically spend the last couple of hours trying different escape sequence but nothing worked :/

Presets

instead of passing the same CLI args everytime, e.g.

$ renamer --find this --replace that *

i want to create a preset, like

$ renamer --find this --replace that * --name renameThisWithThat 

and to use it:

$ renamer --preset renameThisWithThat  *

Regex issue with Git Bash on Windows

image

I am not sure if I am doing something wrong or regex is not working. I am trying to add prefixes to all the files in that folder. but this doesn't seem to work.

Moving files fails if target folder does not exist (yet)

Great tool. It would awesome if it supported operations where "renaming" the file involves moving the file to a new folder:

Consider the following scenario:

  • A directory contains a lot of pictures with a naming format like this:
    /20180716_180000.jpg
    /20180717_210000.jpg
    ...
  • The user (me :) wants to move the files to a folder hierarchy based on the date included in the filename of each file. Desired result:
    /2018-07-16/20180716_180000.jpg
    /2018-07-17/20180717_210000.jpg

Running the following command "works":

renamer --regex --find '^(\d{4})(\d{2})(\d{2})(.*)' --replace '$1-$2-$3/$1$2$3$4' -v *

But it only works if all the destination folders already exist beforehand.
Otherwise, renamer fails with the following error:
"ENOENT: no such file or directory"

Manually creating the destination folders for each file beforehand would be cumbersome/time consuming, better to offload that task to renamer itself :-D

I think that renamer should create the destination folder before moving the file, in order to prevent this error.
This behaviour could be enabled/disabled by a new command line parameter (e.g. --createfolder)

For this purpose, the 'mkdirp' npm package could be used to create all the required subfolders before moving the file.

Compatibility with yarn pnp?

Is this module compatible with Yarn Plug and Play

When running renamer in a Yarn workspace using yarn 2, I get the following error message:

command-line-plugin tried to access command-line-args, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: command-line-args (via "command-line-args")
Required by: command-line-plugin@npm:0.2.0 (via /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/command-line-plugin-npm-0.2.0-94229159f8-3.zip/node_modules/command-line-plugin/)

Require stack:
- /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/command-line-plugin-npm-0.2.0-94229159f8-3.zip/node_modules/command-line-plugin/index.js
- /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/renamer-npm-2.0.0-a2acda74ae-3.zip/node_modules/renamer/lib/cli-app.js
- /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/renamer-npm-2.0.0-a2acda74ae-3.zip/node_modules/renamer/bin/cli.js

See Yarn 2 Release

Thank you for this tool!

Workaround: Downgrading to renamer@^0.7.0 resolves the issue.

Renaming files recursively using regex

Hi,

I have a folder, that contains multiple folders with music files.
All the files in the sub folders has names started by 2 digits, "01, 02, 03,..." followed by song titles.
I wish to remove the song titles, and keeping the first 2 digits in the file names.
I believe this can be done by finding names using regex, but my trials are in vain.

example of the structure

 |-- Main_Folder
     |-- subfolder1
          |-- 01 songtitle.m4a
          |-- 02 songtitle.m4a
          |-- 03 songtitle.m4a
          |-- 04 songtitle.m4a
          |-- 05 songtitle.m4a
     |-- subfolder2
          |-- 01 songtitle.m4a
          |-- 02 songtitle.m4a
          |-- 03 songtitle.m4a
          |-- 04 songtitle.m4a
          |-- 05 songtitle.m4a

I wish it be like this

 |-- Main_Folder
     |-- subfolder1
          |-- 01.m4a
          |-- 02.m4a
          |-- 03.m4a
          |-- 04.m4a
          |-- 05.m4a
     |-- subfolder2
          |-- 01.m4a
          |-- 02.m4a
          |-- 03.m4a
          |-- 04.m4a
          |-- 05.m4a

Can you help me please.

Thanks,
Ajmal

todo list

  • accept input from stdin
  • make more hackable, more easy to insert additional functions into pipeline.. .use(middleware) type approach?
  • maintain a history so we can view and re-run previous renames
  • --js expression and {{js}} token. e.g.:
$ renamer -f file -r 'file{{js}}' --js Date.now() * 
$ renamer -f file -r '{{js}}-file' --js process.cwd() * 
$ renamer -r '{{js}}.txt' --js sprintf("%10s", index) * 
#0000000001.txt
#0000000002.txt
# etc

$ renamer -r '{{index}} ({{js}}).txt' --js moment(new Date()).fromNow() * 
#1 (1 Day ago).txt
#2 (4 Months ago).txt

$ renamer -f '(\w+) -r '{{js}}' --js '$1.toTitleCase()' * 
# filename.txt -> Filename.txt
  • Presets

instead of passing the same CLI args everytime, e.g.

$ renamer --find this --replace that *

i want to create a preset, like

$ renamer --find this --replace that * --name renameThisWithThat 

and to use it:

$ renamer --preset renameThisWithThat  *
  • sign and share presets

Find and replaces multiple times

  1. Is it possible to run multiple find and replace, without entering multiple commands?
    Im new to regex, so the commands below, might needed to optimized

These are my commands
renamer -e -f 'ø' -r 'oe' *
renamer -e -f 'æ' -r 'ae' *
renamer -e -f '_' -r '-' *
renamer -e -f ' ' -r '-' *

  1. Is there an easy way to convert all uppercase letters to lowercase?

Any way to undo?

First I want to congratulate this package. Really simple and powerful.

But is there any way to undo your previous command? It would be very convenient.

Wrong doc?

Spent 1 hour trying to make this work:

renamer --insensitive --find 'mpeg4' --replace 'mp4' *

figured out this is the correct syntax:

renamer --insensitive --find mpeg4 --replace mp4 *

is it just me, or the doc is wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.