How to replace a string in a directory including directory name, file name & file content


I want to create a Rust program that provide a nodeJS template and automaticly replace directory name, file name & file content by the program name chosen by the user.

For instance this a a (simple) nodeJS template


where index.js contains :

  1. I am using the following pattern to match different naming convention

Is there a proper way to fully replace in an entire directory both directory name, file name and content ?

For the moment, I have only find the std::fs::rename but it's pretty basic ?

Thanks in advance,


I found the amazing tool Ruplacer ( that also manage naming convention. I am wandering whether I can use it as a library and not a cmd tool.

This sounds quite similar to cargo-generate, although it looks like you'd need ashleygwilliams/cargo-generate#159.

Even so, you may be able to find some inspiration by skimming through its source code and seeing how they do things.

It looks like it does expose an (undocumented) library API: ruplacer::DirectoryPatcher - Rust. I don't know how helpful it is, but it exists and can be depended on?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.