75lb / renamer Goto Github PK
View Code? Open in Web Editor NEWRename files in bulk.
License: MIT License
Rename files in bulk.
License: MIT License
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.
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?
Is there any way to use this tool programmatically in node.js?
for example:
var renamer = require('renamer');
renamer('this', 'that', '*.js');
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
E.g. I would like to convert "FooBar.txt" to "foobar.txt" on many files.
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!
FR: add typescript support
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
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.
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 ?
Hi.
How do i use renamer within nodejs, ... i.e. const renamer = require('renamer')
?
Preset some naming schemes?
camel
: foo bar
→ fooBar
pascal
: foo bar
→ FooBar
constant
: foo bar
→ FOO_BAR
dot
: foo bar
→ foo.bar
kebab
: foo bar
→ foo-bar
snake
: foo bar
→ foo_bar
title
: foo bar
→ Foo Bar
lower
: FOO BAR
→ foo bar
upper
: foo bar
→ FOO BAR
make easy to insert additional functions into pipeline.. .use(middleware)
type approach?
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.
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?
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
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:
As you can see, it confuses the program a bit.
Also because there's no flag to turn it off, renamer crashes if run on a server which is not internet connected. If you'll excuse me I'm going to go look for a package that isn't spying on me, since all I want to do is rename ****ing files.
Hello,
I'm trying to use renamer without success.
So, I tried with dry-run option, but it doesn't report anything like:
Is there a way to verbose the output to know what it is doing ?
Thanks in advance for your help.
_
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
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!
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
Hey Guys
Thank you for working on this tool.
I do have a need to recursively rename only the files without directories. Is there any way to do this?
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
.
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.
Is there a way to restart the index in each folder?
$ renamer --replace 'Image{{index}}.jpg' **/*.jpg
Before | After |
---|---|
|
|
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.
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...
keep a history so we can easily view and re-run previous renames..
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 :/
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 *
renamer --find /^css$/ --replace wxss --force **/*
can't work
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:
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.
As already mentioned as off-topic in #18, the usage output is formatted wrongly
This is a 1366x768 screen of gnome-terminal:
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.
Right now it can get pretty hard to follow the output from a rename action, especially when things get multiline, it would be awesome if we could get a table layout going on.
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
--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
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 *
These are my commands
renamer -e -f 'ø' -r 'oe' *
renamer -e -f 'æ' -r 'ae' *
renamer -e -f '_' -r '-' *
renamer -e -f ' ' -r '-' *
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.
including integration
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?
this command shouldn't be possible:
$ renamer -f "" -r "" *
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.