Giter VIP home page Giter VIP logo

node-rename-cli's People

Contributors

ckgrafico avatar dependabot[bot] avatar gep13 avatar infusion avatar jhotmann avatar kasparetter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-rename-cli's Issues

Fail more gracefully if EXIF date is missing

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:

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];
returnText = (typeof(data) === 'object' && data.DateTime ? dateFormat(formattedDate, dFormat) : '');

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.

kebab filter seems to be missing (from nunjucks?)

Describe the bug
The kebab filter seems to be missing

To Reproduce:
Steps to reproduce the behavior:

  1. Random File.pdf
  2. rename *.pdf "{{ f | kebab }}"
  3. Error:
/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:

  • OS: macOS 12.2
  • iTerm2/fish
  • Rename Version 7.0.2

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.

id3 tag support

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

Proceed after a single character without having to press enter

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

Custom variable replacements

Add ability for users to add custom variable replacements.

  • Create ~/.rename/replacements.js
  • Merge custom replacements with built-in replacements (if there's a conflict prefer built-in or user?)
  • Add error handling so if replacement fails the user is presented with a better error

Display relative path names in the rename summary

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.

Arch linux DWM

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

Add ability to move files

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.

  • Add ability to move files
  • Add option --nomove to prevent moving files
  • Don't fail if directory doesn't exist (maybe add to conflicts?)
  • Prompt if directory doesn't exist and prompt or verbose options are passed
  • Create directories automatically if force option passed
  • Add option --createdirs to automatically create directories
  • Warn if --nomove and --createdirs passed at the same time if verbose option passed

Easier possibility to rename with changing the file type.

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.

Regex variables

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.

Bad case: rename *.pdf {{f|replace(".","")}}

As mentioned in :

62af80c#r40840287

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:-)

natural sort

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

https://en.wikipedia.org/wiki/Natural_sort_order

Error: Cannot find module 'jpeg-exif'

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 :-)

Provide (or document) an option to ignore directories

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.

Undo rename

Store last rename operation and undo renames with rename -u or rename --undo

stats.ctime cannot be used to retrieve the creation time

First of all: This is a really awesome tool and exactly what I was looking for! 😍

case 'cr':
case 'create':
case 'cr[eate]': {
printIfVerbose(fileObj, 'Formatting ' + fileObj.base + ' create date to: ' + format);
let stats = fs.statSync(fileObj.dir + '/' + fileObj.base);
if (stats.ctime) returnText = dateFormat(stats.ctime, format);
break;
}

ctime:

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.

Add ability to sort input files

Currently input files are sorted in alphabetical order. There should be other ways to sort the file array.

  • reverse alpha
  • dates (created/modified/accessed) and reverse
  • regex sub-string (fallback to filename if no match) and reverse
  • file size and reverse (directories count as 0?)

Separate verbose from prompt

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.

[FIXED] Windows binary

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.

Add Unit Tests

  • Test all options individually
  • Test all variables and their options individually
  • Test options in combination
  • Test variables in combination
  • Test file/folder names with various characters, spaces, and combinations
  • Test moving files
  • Tests for Windows
  • Tests for Linux
  • Tests for MacOS
  • Write even more tests

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.