So I have a bunch of files I want to sort into folders. The nameing scheme is as follows:

```
text_1_text_-66_text_.mrc
text_1_text_-63_text_.mrc
text_1_text_-60_text_.mrc
text_1_text_-57_text_.mrc
text_2_text_-66_text.mrc
text_2_text_-63_text.mrc
text_2_text_-60_text.mrc

```

and so on (the actual number of files is plus to minus 66 so text\_1 has a lot more for example). I want to sort by the first number (so the 1 in text\_1\_...) I have a script that I used to previously sort files:

```
import os
import shutil

n = 1

while (n < 500):
    if os.path.isfile('Stack_%d.txt' % (n)): 
        directory = 'Stack_%d' % (n)
        os.makedirs(directory)
        shutil.move('Stack_%d.txt' % (n), 'stack_%d' % (n))
        shutil.move('Stack_%d_shifts.txt' % (n), 'stack_%d' % (n))
        shutil.move('Stack_%d.mrc' % (n), 'stack_%d' % (n))
        shutil.move('Stack_%d.rawtlt' % (n), 'stack_%d' % (n))
    else:
        n = n+1

```

This is a bit crude but worked fine to sort those files. In an ideal world I would like to just know a command similar to \* in bash that means I can just use string substitution for the beginning of each and then \* the rest of the quote. 

Sorry I am pretty new to programming and all my use cases seem to be small scripts so getting there slowly.