DEV Community

Cover image for Copy paste source files to destination with singular and plural replace text in file contents and file paths
ILshat Khamitov
ILshat Khamitov

Posted on

Copy paste source files to destination with singular and plural replace text in file contents and file paths

I often have to copy a large number of files and folders with the base code and replace various lines inside the files, as well as in the names of files and folders, and this takes a lot of time 😒.

To solve this problem, I wrote a utility that can do it for me 😎.

Links

https://www.npmjs.com/package/rucken - npm package

https://github.com/rucken/rucken/blob/develop/libs/rucken/src/lib/copy-paste/copy-paste.service.ts - source code

https://www.npmjs.com/package/case-anything - main library used

Example of usage

1) Create folder cat-dog

mkdir cat-dog
Enter fullscreen mode Exit fullscreen mode

2) Create txt file cat-dog/cat_dog.txt

echo "catDog
CatDog
cat-dog
cat_dog
CAT_DOG
Cat-Dog
Cat_Dog
CAT-DOG
cat Dog
Cat Dog
cat dog
CAT DOG
catDogs
CatDogs
cat-dogs
cat_dogs
CAT_DOGS
Cat-Dogs
Cat_Dogs
CAT-DOGS
cat Dogs
Cat Dogs
cat dogs
CAT DOGS" > cat-dog/cat_dog.txt
Enter fullscreen mode Exit fullscreen mode

3) Run the utility

npx rucken copy-paste --find=cat-dog --replace=human-ufo --path=./cat-dog
Enter fullscreen mode Exit fullscreen mode

4) Check new file

echo ./human-ufo/human_ufo.txt
Enter fullscreen mode Exit fullscreen mode

Result

humanUfo
HumanUfo
human-ufo
human_ufo
HUMAN_UFO
Human-Ufo
Human_Ufo
HUMAN-UFO
human Ufo
Human Ufo
human ufo
HUMAN UFO
humanUfos
HumanUfos
human-ufos
human_ufos
HUMAN_UFOS
Human-Ufos
Human_Ufos
HUMAN-UFOS
human Ufos
Human Ufos
human ufos
HUMAN UFOS

Enter fullscreen mode Exit fullscreen mode

If you can’t run it through npx, then you need to install the utility globally

Install

npm i -g rucken
Enter fullscreen mode Exit fullscreen mode

Usage

rucken copy-paste --find=cat-dog --replace=human-ufo --path=./cat-dog
Enter fullscreen mode Exit fullscreen mode

I hope this utility will help developers save time πŸ˜‰

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay