75lb/renamer

Is there a way to change the case of a pattern?

tandrewnichols opened this issue · 9 comments

E.g. I would like to convert "FooBar.txt" to "foobar.txt" on many files.

75lb commented

which OS are you on, i assume you're on a case-insensitive OS (Mac or Windows)?

OSX Yosemite. Yeah, it's case-insensitive, but that actually doesn't matter in this case. Context:

I'm using grunt spritesmith to generate a spritesheet of a bunch of images, and it uses the filenames to generate CSS classes, and it preserves the casing of the filenames.

75lb commented

this boils down to case-insensitivity at the OS level.. node essentially considers these two files the same, thus renamer doesn't think there's any work to do..

> fs.existsSync('file2.test')
true
> fs.existsSync('File2.test')
true

i'm flippin starving now but will fix it later!

I was able to do it with pure bash, though it wasn't easy because of the filesystem case-insensitivity. It kept thinking I was moving a file to the exact same name and wouldn't let me, so I had to move them to a temp directory as I lower cased them, and then move them back. Anyway, the point is, it's not urgent for me. I have the files now in the form I need them. But something like --transform lowercase could be a nice addition to the tool. It seems like, regardless of the file system, you could, in that case, call String.toLowerCase on the filename before writing it no matter what.

I always keep my project files in a case sensitive partition, this would be pretty handy to have +1

I thought that a solution could be a "pre defined function" argument (--fn/-s) to identify a function (maybe from string.js -- humanize, camelize, dasherize, etc) to receive the fileName after replacements. It could solve this and be a useful feature. What do you think?

75lb commented

@wellguimaraes yeah, would be useful to have the option to pass in a custom transform function if the built-in case-insensitive rename didn't cover your needs.. that will likely go in the next version.

75lb commented

It's now possible to change a file's case in renamer v1.0.0 (prerelease available here).

On case-insensitive systems, this command (renaming FILE.jpg to file.jpg) will fail as the target file already exists.

$ renamer --replace file.jpg FILE.jpg

In renamer v1, you can override this by passing --force.

$ renamer --replace file.jpg FILE.jpg --force

Version 1 is still in prerelease so feedback welcome at this stage!

75lb commented

fixed and released in renamer v1.0.0.

@wellguimaraes , there's a new plugin to achieve what you suggested here.