marcusbuffett / pipe-rename

Rename your files using your favorite text editor
https://crates.io/crates/pipe-rename
MIT License
397 stars 12 forks source link

Error: Nonexisting input files. Aborting. #45

Closed lamyergeier closed 1 year ago

lamyergeier commented 2 years ago

Error is shown even if file exists!

$ ls
PARSIFAL - Bavarian State Opera-1.mp4  PARSIFAL - Bavarian State Opera-3.mp4
PARSIFAL - Bavarian State Opera-2.mp4  PARSIFAL - Bavarian State Opera.mp4
$ ls | renamer 
The following input files do not exist:
PARSIFAL - Bavarian State Opera-1.mp4  PARSIFAL - Bavarian State Opera-3.mp4
PARSIFAL - Bavarian State Opera-2.mp4  PARSIFAL - Bavarian State Opera.mp4

Error: Nonexisting input files. Aborting.
$ ls -la
total 573M
664 -rw-rw-r-- 1 nikhil nikhil 123M 2022-04-15 19:57 PARSIFAL - Bavarian State Opera-1.mp4
664 -rw-rw-r-- 1 nikhil nikhil 123M 2022-04-15 19:57 PARSIFAL - Bavarian State Opera-2.mp4
664 -rw-rw-r-- 1 nikhil nikhil 169M 2022-04-15 19:57 PARSIFAL - Bavarian State Opera-3.mp4
664 -rw-rw-r-- 1 nikhil nikhil 161M 2022-04-15 19:41 PARSIFAL - Bavarian State Opera.mp4
$  renamer  *.mp4
Error: No replacements found
mtimkovich commented 2 years ago

Would you happen to be on FreeBSD?

lamyergeier commented 2 years ago

Ubuntu 20.4

mtimkovich commented 2 years ago

I can't replicate this on my machine 😕 Does this only happen for files with spaces or does this happen every time?

Are you able to compile the code? If so what happens if you run renamer with this line commented?

https://github.com/marcusbuffett/pipe-rename/blob/53a97b850c9b55ffb68ad4c81cca524eca170eb4/src/main.rs#L328

assarbad commented 2 years ago

Error is shown even if file exists!

$ ls
PARSIFAL - Bavarian State Opera-1.mp4  PARSIFAL - Bavarian State Opera-3.mp4
PARSIFAL - Bavarian State Opera-2.mp4  PARSIFAL - Bavarian State Opera.mp4

But these two files (!) do not exist, do they 😉?

And that is the reason why you shouldn't use ls as input for pipes in general or parse its output, especially without some basic precautions. E.g. using ls -1 (and yes, some ls flavors will turn this on when they detect a pipe) or ls -Q (no idea if this would work, given how renamer implements its logic) etc.

The appropriate (and more powerful) option is to use find -type f if you want to really pipe the input, but renamer will also happily do renamer * for this particular case (proved by the output in your own initial comment).

$ ls | renamer 
The following input files do not exist:
PARSIFAL - Bavarian State Opera-1.mp4  PARSIFAL - Bavarian State Opera-3.mp4
PARSIFAL - Bavarian State Opera-2.mp4  PARSIFAL - Bavarian State Opera.mp4

Error: Nonexisting input files. Aborting.

Yep, clearly they don't exist as your subsequent ls -la proves. At least I don't see two files named:

Your shell should have done the right thing for you with renamer * and renamer would have interpreted it correctly (actually it did as the last line of output you provided proves).

What shell are you using? Perhaps provide the output of the following commands:

$SHELL --version; env|grep -E '^(LC_|LANG|EDITOR)'
assarbad commented 2 years ago

@mtimkovich @marcusbuffett I strongly suggest closing this. This seems to be a case of wrong usage rather than a defect in renamer as I showed in my previous comment.