How can I rename a bunch of files and give them individual names? C++ and/or python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I rename a bunch of files and give them individual names? C++ and/or python

Hi all. I often have many jpg and png files which I want to rename. I have a list of names which should replace the automatically created name. So for example "file1.jpg" should replaced by "xy_number1_name1" and so on. I have Visual Studio and it would be great to do it with c++ or Python. Thanks for your help.

2nd Feb 2019, 11:20 AM
Niggo
2 Answers
+ 7
C++ has std::rename() for files. https://en.cppreference.com/w/cpp/io/c/rename The next problem would be about figuring out how to iterate through a folder of files, // e.g. for (File i : Folder) { ... } I've done it in Java before, but not in C++. A one-minute lookup into the documentations give information about std::filesystem. It works, but is exclusive to C++17 (perhaps also C++14 on experimental config). https://en.cppreference.com/w/cpp/filesystem/directory_iterator Python? Probably very easy, but I don't know. :P
2nd Feb 2019, 1:34 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Maybe you can use a external tool like totalcommamder? or a opensource libary that support file management.
3rd Feb 2019, 7:52 AM
Han
Han - avatar