Search code examples
gitmv

How to change multiple file names in the same format with git on Windows 10?


I have hundreds of files called tutorial_xx.cpp, where xx is a number from 1 to 99. I reached the three-digit mark, and now I have to change all the file numbers so that I can keep track of chronological order. I was thinking that, if I can add a 0 between tutorial_ and xx.cpp I could achieve this, but apparently this didn't work:

git mv tutorial_*.cpp tutorial_0*.cpp

Is it possible to successfully do such a thing in git? And if so, how?


Solution

  • If in git-bash, you could try:

    for name in tutorial_*.cpp;do
        git mv $name ${name/_/_0/}
    done
    

    If you have Python installed, try:

    python -c "import os;map(lambda x:os.rename(x,x.replace('_','_0',1)),filter(lambda x:'tutorial_' in x, os.listdir('.')))"