jhotmann / node-rename-cli Goto Github PK
View Code? Open in Web Editor NEWA tool for renaming files quickly, especially multiple files at once.
Home Page: https://jhotmann.github.io/node-rename-cli/
License: MIT License
A tool for renaming files quickly, especially multiple files at once.
Home Page: https://jhotmann.github.io/node-rename-cli/
License: MIT License
rename picture-without-exif.jpg '{{exif|date}} {{f}}'
results in
/usr/local/lib/node_modules/rename-cli/lib/replacements.js:419
let formattedDate = data.DateTime.split(/:|\s/)[1] + '/' + data.DateTime.split(/:|\s/)[2] + '/' + data.DateTime.split(/:|\s/)[0] + ' ' + data.DateTime.split(/:|\s/)[3] + ':' + data.DateTime.split(/:|\s/)[4] + ':' + data.DateTime.split(/:|\s/)[5];
^
TypeError: Cannot read property 'split' of undefined
at Object.function (/usr/local/lib/node_modules/rename-cli/lib/replacements.js:419:45)
at replaceVariables (/usr/local/lib/node_modules/rename-cli/rename.js:289:89)
at /usr/local/lib/node_modules/rename-cli/rename.js:50:29
at Array.forEach (<anonymous>)
at Object.getOperations (/usr/local/lib/node_modules/rename-cli/rename.js:33:9)
at renameFiles (/usr/local/lib/node_modules/rename-cli/bin.js:79:27)
at parseArgs (/usr/local/lib/node_modules/rename-cli/bin.js:66:5)
at /usr/local/lib/node_modules/rename-cli/bin.js:50:7
at /usr/local/lib/node_modules/rename-cli/node_modules/graceful-fs/graceful-fs.js:115:16
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
(Obviously, the above example is construed. I encountered the problem while renaming a bunch of files with rename *
and now I have to sort out the pictures without EXIF manually.)
The problem is that the check on data.DateTime
comes one line too late:
node-rename-cli/lib/replacements.js
Lines 419 to 420 in 5d75fdc
The existing intention seems to be to just return/use an empty string in such a case. I think it would also be desirable to get a warning on the console in such a case (and maybe skip renaming the file or use a string like ERROR
or NOEXIF
instead). I don't have a strong preference other than that code shouldn't crash and continue with the remaining files.
Describe the bug
The kebab
filter seems to be missing
To Reproduce:
Steps to reproduce the behavior:
Random File.pdf
rename *.pdf "{{ f | kebab }}"
/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/src/lib.js:36
err = new Error(old.message);
^
Template render error: (unknown path)
Error: filter not found: kebab
at Object._prettifyError (/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/src/lib.js:36:11)
at /Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/src/environment.js:563:19
at Template.root [as rootRenderFunc] (eval at _compile (/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/src/environment.js:633:18), <anonymous>:17:3)
at Template.render (/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/src/environment.js:552:10)
at Environment.renderString (/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/src/environment.js:380:17)
at Object.renderString (/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/node_modules/nunjucks/index.js:99:14)
at Operation.replaceVariables (/Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/src/operation.js:40:34)
at async /Users/luke/.local/share/nvm/v17.4.0/lib/node_modules/rename-cli/src/batch.js:29:68
Expected behavior
For file to be renamed random-file.pdf
Desktop:
Been seeing this one for a while, finally getting around to opening an issue. Obviously the workaround is just to do "{{ f | replace(' ', '-') | lower }}"
, but I thought you'd want to know.
Just checked the rest of the built in filters, same error with snake
as well.
example
filename "me & joe"
run the command
rename * "{{f|replace('me', 'ben')}}"
result filename "ben & joe"
instead of "ben & joe"
Get OS name, current user, and things like that
Is your feature request related to a problem? Please describe.
Renaming your music library is a common task. Add id3 tag support so rename-cli can be used to rename/restructure a music library.
Describe the solution you'd like
Add a id3 object with sub-properties for common id3 tags
This is really a detail but using this tool would be faster (and thus more pleasurable) if the prompts would continue after entering a single character without having to press enter. Both for:
Would you like to proceed? (y/n)
and
[…] already exists. What would you like to do?
1) Overwrite the file
2) Keep both files
3) Skip
Please input a number:
I'm not sure whether this is easily possible with the package that you are using. In Bash, I like to use the following:
read -p "Would you like to proceed? (y/n) " -n 1 -r
echo
if [ $REPLY = 'y' ]
then
echo "Proceed."
else
echo "Abort."
fi
Add ability for users to add custom variable replacements.
When renaming with rename --verbose '**/*.*' …
, you cannot see which files reside in which directory. It would be useful either to see the file path relative to the working directory or to group the renames by directory. If this is not desirable as a default, such a feature could also be opt-in with an option.
sudo npm i -g rename-cli@beta
npm WARN deprecated [email protected]: The package has been renamed to open
npm WARN deprecated [email protected]: request has been deprecated, see request/request#3142
npm WARN deprecated [email protected]: this library is no longer supported
/usr/bin/rname -> /usr/lib/node_modules/rename-cli/bin.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/rename-cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code EEXIST
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/rename-cli/bin.js
npm ERR! dest /usr/bin/rename
npm ERR! errno -17
npm ERR! EEXIST: file already exists, symlink '../lib/node_modules/rename-cli/bin.js' -> '/usr/bin/rename'
npm ERR! File exists: /usr/bin/rename
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-12-06T08_23_48_335Z-debug.log
sudo npm i -g rename-cli@beta 36.60s user 6.90s system 34% cpu 2:07.72 total
The wizard is terribly out of date...
Currently when you use rename, it will always keep the file in the same directory. Add ability to move files as well and an option to turn off file moving.
--nomove
to prevent moving files--createdirs
to automatically create directories--nomove
and --createdirs
passed at the same time if verbose option passedIs it possible to navigate using arrow keys or have I just missed it in the document?
Hi. That would be nice if i can rename the file "as is". For example. Now i'f i'm trying to do this
rename file.cfg file.txt i'm getting error and i need to do a lot of things to just change the file type. That would be nice if app will not crash if i'm attempting to do that and i can just rename file.cfg to file.txt easy and without any other operations.
Add ability to specify regex named groups that become replacement variables
Example: consider the file "Expense Report - Jordan 2-18.pdf" and several other files with similar names but different report name, people names, and dates.
You could use the regex /(?'Title'.+(?=\s\-))|(?'Name'(?<=\-\s)[A-Za-z]+)/
to get the report name and person and then use {{Title}} and {{Name}} in the output file name. This way you could use parts of the original file name without copying the whole thing.
As mentioned in :
Bad cases:
rename *.pdf {{f|replace(".", "")}} // expect: "abcdefg...pdf" ==> "abcdefg.pdf"
rename *.pdf {{f|regexReplace("\\d+", "")}} // expect: 'abcdefg01234.pdf' ==> "abcdegf.pdf"
// however, we will get "Invalid command".
Maybe we can fix it in future:-)
I have a list of files like this:
test1.txt
test10.txt
test2.txt
test3.txt
test4.txt
test5.txt
test6.txt
test7.txt
test8.txt
test9.txt
I want to rename them to
document_01.txt
document_02.txt
....
But I can't sort the files in a way that test10.txt is the last file.
Solution:
Add support for --sort natural
Hey guys,
i've got a tiny litte problem and hope that you can help me :-)
when i try to rename a existing file then it throws me an error
> rname -f <previousfilename> <newfilename>
internal/modules/cjs/loader.js:596
throw err;
^
Error: Cannot find module 'jpeg-exif'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/sebastian/.nvm/versions/node/v10.4.1/lib/node_modules/rename-cli/lib/replacements.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
thanks :-)
Add ability to use EXIF data from jpg photos in output file name
This issue started out as a wish for an enhancement, but, as it turned out, it's also a bug.
When renaming files with rename '*'
or rename '**/*'
, I would like to be able to only rename files but not directories without enforcing any naming conventions. My current workaround is to use rename '**/*.*'
because my directories rarely contain periods while all the files I'm interested in typically have a suffix.
Now to the bug part: If you rename with '**/*'
files in a subdirectory and the directory itself is also renamed (due to the "limitation" described above), then the command fails on all files in the subdirectory with <filepath> does not exist! Operation skipped.
. Ideally, the tool would either rename directories last or keep track of the renames dynamically.
Store last rename operation and undo renames with rename -u
or rename --undo
First of all: This is a really awesome tool and exactly what I was looking for! 😍
node-rename-cli/lib/replacements.js
Lines 264 to 271 in 5d75fdc
ctime
stands for status change time. This timestamp tells you when was the last time the property and metadata of the file were changed. The metadata includes file permissions, ownership, name and location of the file.
Please use stats.birthtime
for this (see this documentation for platform availability).
In other words, with {{date|create}}
you get when the file content or its name was last changed. Until this is fixed, I will just use {{date|modify}}
instead, which at least ignores file renames.
Currently input files are sorted in alphabetical order. There should be other ways to sort the file array.
I would like to be able to confirm the renaming before proceeding without getting information like:
---Date Start---
Formatting test.png modify date to: yyyy-mm-dd
returning: 2020-03-12
---Date End---
This could be achieved with a separate option such as -p
or --prompt
.
Dear Mr. Hotmann,
Could you be so kind to generate .exe
for the rest of us who use Windows w/o Node?
I’m told that either Nexe or EnclosureJS might help you to achieve that.
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.