Create new folder (based on partial filename) then move files to that folder

I have a single folder containing files in this format

0167565-2017-06-01.pdf
0167565-2017-10-02.pdf
222648M-2017-08-01.pdf
222648M-2017-09-01.pdf
3082353642-2021-12-31.pdf
3082353642-2022-02-01.pdf
3082353642-2022-03-01.pdf

To the left of the first occurrence of the hyphen is always the account number.
I would like to create a directory for the account number then move all files of that account number to that directory.

The end result would be this.
0167565
-0167565-2017-06-01.pdf
-0167565-2017-10-02.pdf
222648M
-222648M-2017-08-01.pdf
-222648M-2017-09-01.pdf
3082353642
-3082353642-2021-12-31.pdf
-3082353642-2022-02-01.pdf
-3082353642-2022-03-01.pdf

Parameters for the Advanced Renamer
Mode: Regular Expressions
Old name: (.*?)-.*
New name: \1\\\0
Ignore extension: checked

1 Like

That is so simple. Thank you so much.
If i wanted to remove the part i used to create the folder how would i do that?

ex
0167565
-2017-06-01.pdf
-2017-10-02.pdf

Parameters for the Advanced Renamer
Old name: (.*?)-(.*)
New name: \1\\\2

Hi lxp I just want to understand what does mean by \1\\\0. Here \1 means the first matched group of my regexp which is (.*?) in that case. but after that \\ and \0 means what?

\0 in a regex replacement string will insert the whole original name.

1 Like

And why are the double back slash \\ for?

With regex, \\ turns into a literal \ (since \ on its own gives special meaning to the next character).

1 Like